Virajsinh

FileHandling_10_Binary_Read

Dec 4th, 2017
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.40 KB | None | 0 0
  1. //Read Binary File fread();
  2.  
  3. #include<stdio.h>
  4. #include<conio.h>
  5.  
  6. void main()
  7. {
  8.     FILE *fp;
  9.     char str[11];
  10.     clrscr();
  11.    
  12.     fp = fopen("welcome.txt", "r+");
  13.    
  14.     if(fp==NULL)
  15.     {
  16.         printf("\n The file could not be opened");
  17.         exit(1);
  18.     }
  19.    
  20.     //fread();
  21.     fread(str, 10, 1, fp);
  22.    
  23.     str[10]= '\0';
  24.    
  25.     printf("\n First 10 characters of the file are : %s", str);
  26.    
  27.     fclose(fp);
  28.     getch();
  29. }
Add Comment
Please, Sign In to add comment