Advertisement
Istanvir389

File Open Read And Write

Nov 7th, 2017
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.51 KB | None | 0 0
  1.     READ MODE
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4.  
  5. int main()
  6. {
  7.  
  8.     int i;
  9.     FILE *fp;
  10.     fp=fopen("D:\\newfile.txt","w");
  11.    // fputs("123456",fp);
  12.    for(i=1;i<=10;i++)
  13.    {
  14.        fprintf(fp,"%d\n",i);
  15.    }
  16. fclose(fp);
  17.  
  18. }
  19.  
  20.  
  21.  
  22.  
  23.  
  24. WRITE MODE
  25.  
  26.  
  27. #include<stdio.h>
  28. #include<stdlib.h>
  29.  
  30. int main()
  31. {
  32.     FILE *fp;
  33.     fp=fopen("D:\\newfile.txt","r");
  34. int i,num;
  35.   char c[100];
  36.  
  37.  
  38. for(i=1; i<=10; i++)
  39. {
  40.     fscanf(fp,"%d\n",&num);
  41.     printf("%d\n",num*num);
  42. }
  43. fclose(fp);
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement