HI
I am trying to stream a file in and then stream out the line to a different file
example:
CString fileSource ="in.txt";
CString fileDest ="out.txt";
FILE *in_stream;
FILE *out_stream;
char line[100];
if( (in_stream = fopen( fileSource, "r" )) != NULL )
{
if(out_stream = fopen(fileDest,"w")) !=NULL)
while( fgets( line, 100, in_stream )){
.... //do something with the line and then output it
fprintf(out_stream, "%s", line);
}
fclose(out_stream);
}
fclose( in_stream );
}
both files are opened and the first line is read.
after that nothing happens.
I cannot get this to work.
I have heard of memory mapping files but I have no Idea how to do this, or if it would solve my problem.
Thanks for any suggestions.
The fgets just worked fine. It should work.
try copying other files. do ypu get the same errror.
Sometimes you get those type of errors if you try to copy binary files. Are u trying to copy binary files.
For text files, your code works fine.
another cause might be that. you are using it in a function. If u call the function first time it will copy. close the handle. In the second time it start copying from the first. In case your src is changing, at the end of your program, you will ger the last entry only.
to avoid this open the file just once (somewhere in main()) and close in the end of the program. This can solve your problem.
If you just want to try out, open fileDest as "a+"(append).
regards manish