easy way (not best)
#include int ReadAndStore(char lines[1024][1024])
{
int numberOfLinesRead = 0;
int i;//index
//try to open the file
FILE\* theFile = fopen("somefile", "r");
if(theFile==NULL)//if it fails
return -1; //exit this function with -1
//read the file into lines
printf("Opened file for reading\\n");
numberOfLinesRead = 0;
while(fgets(lines\[numberOfLinesRead\],1023,theFile)&&numberOfLinesRead<1024)
{
//you can also print your data here
printf("%s", lines\[numberOfLinesRead\]);
//increment line index;
numberOfLinesRead++;
}
fclose(theFile);
//print data to screen
return numberOfLinesRead;//job well done
}
int main(int argc, char *argv[])
{
printf("scream if this is to big\n");
char fileContents[1024][1024];//should be enough
printf("i didn't scream\n");
int i;
int result = ReadAndStore(fileContents);
//if read returned 1..we exit
if(result==-1)
{
printf("Error reading file");
return 1;
}
FILE \*out = fopen("outfile","w");
if(out==NULL)
{
printf("Error opening file");
return 1;
}
//print lines to out
for(i = 0;i<result;i++)
fputs(fileContents\[i\],out);
printf("i've read %d lines\\n",result);
//close file
fclose(out);
return 0;
}