akashtadwai

File I/O

Nov 29th, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1.  
  2. # include <stdio.h>
  3. int main( )
  4. {  
  5.     FILE *filePointer,*fo ;
  6.     int n;
  7.     filePointer = fopen("input.txt", "r") ;
  8.     fo=fopen("output.txt","w");
  9.     if ( filePointer == NULL )
  10.     {
  11.         printf( "Failed to open \n" ) ;
  12.     }
  13.     else
  14.     {
  15.         printf("The file is now opened.\n") ;
  16.         fscanf(filePointer,"%d",&n);
  17.         int arr[n],i=0;
  18.         fscanf(filePointer,"%d",&n);
  19.         while(fscanf(filePointer,"%d",&arr[i])!=EOF){
  20.             i++;
  21.         }
  22.         for(int i=0;i<n;i++){
  23.             fprintf(fo,"%d ",arr[i]);
  24.         }
  25.         fclose(filePointer) ;
  26.         fclose(fo);
  27.         printf("The file is now closed.") ;
  28.     }
  29.     return 0;        
  30. }
Add Comment
Please, Sign In to add comment