IPB

Welcome Guest ( Log In | Register )



Tags
This content has not been tagged yet
 
Reply to this topicStart new topic

Weird Characters Appending To File


kvarnerexpress
no avatar
Super Member
*********
Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



Post #1 post Mar 30 2005, 10:04 PM
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.
Go to the top of the page
+Quote Post
dexter
no avatar
Advanced Member
*******
Group: Members
Posts: 142
Joined: 24-December 04
From: Queensland, Australia
Member No.: 2,902



Post #2 post Apr 3 2005, 12:09 PM
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)
Go to the top of the page
+Quote Post
cse-icons
no avatar
Super Member
*********
Group: Members
Posts: 351
Joined: 19-October 04
From: India
Member No.: 1,824



Post #3 post Apr 14 2005, 09:05 AM
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.
Go to the top of the page
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No New Posts   8 -Pandemonium- 496 25th August 2004 - 04:00 PM
Last post by: -Pandemonium-
No New Posts 3 BoSZ 406 28th September 2004 - 11:12 AM
Last post by: BoSZ
No New Posts 6 dozen 285 9th September 2004 - 11:58 PM
Last post by: Triple X
No New Posts   4 annylei 297 14th September 2004 - 09:38 PM
Last post by: Triple X
No New Posts 9 jailbox 346 10th October 2004 - 08:01 AM
Last post by: whatknows
No New Posts   3 josh_sg1 355 12th October 2004 - 12:02 AM
Last post by: s2city
No New Posts   0 dontmaimyourself 376 10th October 2004 - 12:51 PM
Last post by: dontmaimyourself
No New Posts   0 sonesay 900 11th July 2007 - 10:50 PM
Last post by: sonesay
No New Posts   8 sohahm 343 21st October 2004 - 08:44 PM
Last post by: beg4mercy
No New Posts   0 sohahm 208 16th October 2004 - 01:46 AM
Last post by: sohahm


 



RSS Lo-Fi Version Time is now: 4th December 2008 - 06:48 PM