#include //Text data int main() { FILE* cfPtr ; if ( (cfPtr = fopen( "data2.txt" , "w" ) ) == NULL ) { printf( "File could not be opened.\n" ); } else { fputs( "This is a line.\n" , cfPtr) ; fprintf( cfPtr, "This is the second line.\n" ) ; int x1=100 ; fprintf( cfPtr, "%d\n" , x1 ) ; fclose ( cfPtr ); } char buffer[100] ; if ( (cfPtr = fopen( "data2.txt" , "r" ) ) == NULL ) { printf( "File could not be opened.\n" ); } else { fgets( buffer ,100, cfPtr ) ; printf( "%s\n" , buffer ) ; //Problem because of spaces //Will read only one word fscanf( cfPtr, "%s" , buffer ) ; printf( "%s\n" , buffer ) ; //Read rest of the line fgets( buffer ,100, cfPtr ) ; printf( "%s\n" , buffer ) ; //Read the integer //fgets( buffer ,100, cfPtr ) ; //printf( "%s\n" , buffer ) ; int x1 ; fscanf( cfPtr, "%d\n" , &x1 ) ; printf( "x1 is %d\n" , x1 ) ; fclose ( cfPtr ); } return 0; }