kvarnerexpress 0 Report post Posted March 30, 2005 Anytime I open a file and close it without changes, weird characters show up. Here is the code:PHP Code:inFile = fopen("serefs.dat","rb"); outFile = fopen("tempfile.dat","wb"); while (!feof(inFile)) { char line[512]; char timeline[11]; fgets(line,512,inFile); strncpy(timeline, line, 10); timeline[11] = '\0'; int filetime; filetime = atoi(timeline); if(filetime > (realtime - 86400)) { fputs(line,outFile); } } fclose(inFile); fclose(outFile); //Put tempfile in buffer inFile = fopen("tempfile.dat","rb"); fseek (inFile , 0 , SEEK_END); size2 = ftell (inFile); rewind (inFile); buffer = (char*) malloc (size2); fread (buffer,1,size2,inFile); fclose (inFile); //Copy buffer to serefs.dat outFile = fopen("serefs.dat","wb"); if(outFile != NULL) { fputs(buffer,outFile); } free (buffer); fclose(outFile); Now I know I can add a counter, then add a condition to only copy tempfile to serefs if counter is not equal to 0. But that wouldn't satisfy my curiosity as to why those weird characters happen. Here is an example. "0 @0 @"This ONLY happens *after* the file has already been opened once with no modifications. Share this post Link to post Share on other sites
dexter 0 Report post Posted April 3, 2005 I'm not overly familiar with C style filehandling. If you're using MSVC++ 6.0 as you said in your previous post, why not use C++ filestreams? (in the 'fstream' header) Share this post Link to post Share on other sites
cse-icons 0 Report post Posted April 14, 2005 If possible can you post the file "serefs.dat". and also the output file that gets generated with wierd characters.I will try to execute it and might be able to debug the problem.Alos, please use BBCode 'CODE' to put your code so that it is more readable.Cheers. Share this post Link to post Share on other sites