ok so i know how to program in JAVA..
i am trying to learn C but the language is pretty confusing..
so i want to read from a file..
i created a FILE, numbers.txt ---> this file has int values.
i have code to read the file, now i am confused as to how to manipulate the data from the file?
for instance maybe sum up the data with a for loop and maybe print out the sum to a different file?
do i make n e sense?
sorry guys:(
________C O D E_______________
#include<stdio.h>
#include<stdlib.h> // infile
int main(void){
int sum = 0;
char filename[] = "numbers.txt";
FILE *file = fopen ( filename, "r" );
if ( file != NULL )
{
char line [100]; /* or other suitable maximum line size */
while ( fgets ( line, sizeof line, file ) != NULL ) /* read a line */
{
fputs ( line, stdout ); /* write the line */
}
fclose ( file );
}
else
{
perror ( filename );
}
return 0;
}