Advertisement
TheWhiteFang

[C] File read/write operation

Nov 10th, 2014
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include<stdio.h>
  3.  
  4.  
  5. int main(){
  6.    
  7.     FILE *fp;
  8.     int value = 0, rel = 0;
  9.  
  10.     //create new file with write mode
  11.     fp = fopen("one.txt","w");
  12.  
  13.     printf("\n Enter the value to write: ");
  14.     scanf("%d",&value);
  15.  
  16.     //writing value to file
  17.     //putw(value, fp);
  18.     fprintf(fp, "%d", value);
  19.  
  20.     //closing file from write mode
  21.     fclose(fp);
  22.  
  23.     //opening file with read mode
  24.     fp = fopen("one.txt","r");
  25.    
  26.     //reading value from file
  27.     //rel = getw(fp);
  28.     fscanf(fp, "%d", &value);
  29.  
  30.     printf("\n The result is:%d\n", value);
  31.  
  32.     //closing file from write mode
  33.     fclose(fp);
  34.    
  35.  
  36.     return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement