|
|
|
|
![]() ![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 407 Joined: 13-December 04 Member No.: 2,696 |
Post
#1
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. |
![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 142 Joined: 24-December 04 From: Queensland, Australia Member No.: 2,902 |
Post
#2
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)
|
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members
Posts: 351 Joined: 19-October 04 From: India Member No.: 1,824 |
Post
#3
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. |
![]() ![]() |
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
8 | -Pandemonium- | 496 | 25th August 2004 - 04:00 PM Last post by: -Pandemonium- |
|||
![]() |
3 | BoSZ | 406 | 28th September 2004 - 11:12 AM Last post by: BoSZ |
|||
![]() |
6 | dozen | 285 | 9th September 2004 - 11:58 PM Last post by: Triple X |
|||
![]() |
4 | annylei | 297 | 14th September 2004 - 09:38 PM Last post by: Triple X |
|||
![]() |
9 | jailbox | 346 | 10th October 2004 - 08:01 AM Last post by: whatknows |
|||
![]() |
3 | josh_sg1 | 355 | 12th October 2004 - 12:02 AM Last post by: s2city |
|||
![]() |
0 | dontmaimyourself | 376 | 10th October 2004 - 12:51 PM Last post by: dontmaimyourself |
|||
![]() |
0 | sonesay | 900 | 11th July 2007 - 10:50 PM Last post by: sonesay |
|||
![]() |
8 | sohahm | 343 | 21st October 2004 - 08:44 PM Last post by: beg4mercy |
|||
![]() |
0 | sohahm | 208 | 16th October 2004 - 01:46 AM Last post by: sohahm |
|||
|
Lo-Fi Version | Time is now: 4th December 2008 - 06:48 PM |