Jump to content
xisto Community
kvarnerexpress

Weird Characters Appending To File

Recommended Posts

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

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

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.