#include <stdio.h>
int main()
{
// "r" open the file for reading
FILE* fp = fopen( "data2.txt", "r" ) ;
if( fp != NULL ) // if the file was opened
{
// try to read 5 integers from the file
for( int i = 0 ; i < 5 ; ++i )
{
int var ;
if( fscanf( fp, "%d", &var) == 1 ) // if one value was read in (successful scanf)
printf( "%d\n", var ) ; // print the value that was read
else puts( "input failure (failed to read an int)\n" ) ;
}
}
else puts( "failed to open input file" ) ;
}