zero_shubham1

file_h_pointer

Jul 25th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3.  
  4. int main()
  5. {
  6.     FILE *fp;
  7.     int num,i,out_n,length=0;
  8.     char str[50],out[50];
  9.  
  10.     for(i=0;i<3;i++)
  11.     {
  12.         fp = fopen("wrtie_file_test.txt","a");
  13.  
  14.         printf("Enter string: ");
  15.         gets(str);
  16.         printf("Enter a number: ");
  17.         scanf("%d",&num);
  18.  
  19.         fprintf(fp,"%s : %d\n",str,num);
  20.         fflush(stdin);
  21.     }
  22.     fclose(fp);
  23.     fp = fopen("wrtie_file_test.txt","r");
  24.     for(i=0;i<3;i++)
  25.     {
  26.         fscanf(fp,"%s : %d\n",out,&out_n);
  27.         length = length+ftell(fp);
  28.         fseek(fp,length,SEEK_SET);
  29.         fflush(stdin);
  30.         printf("%s : %d\n",out,out_n);
  31.         printf("Pointer location: %d\n",length);
  32.     }
  33.     fclose(fp);
  34.     return 0;
  35. }
Add Comment
Please, Sign In to add comment