Weird Characters Appending To File

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > C/C++ Programming

Weird Characters Appending To File

kvarnerexpress
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.

 

 

 


Reply

dexter
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)

Reply

cse-icons
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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : weird characters appending file

  1. Simple C File Handling In Action - Small code snipet which covers most of basic file handling and navigat (4)
    Yesterday I suddenly got a lot of work. The same work we try to push off, yes you are right all
    formalities to get the code review incorporated and update all source code files with code review
    headers. Imagine if you need to open 300 files one by one and append code review headers at the
    end. Since most files are reviewed in groups of 20 to 30 files. We require one header to be placed
    in say 20 to 30 files. To simplify I went back to my class assignment days and wrote this small c
    utility to open all files passed on command line and open attach code review headers an...
  2. Encrypting A File - (5)
  3. Reactions To A Busy File - (2)
    I just wanted to know if let's say you have a file called tempfile.dat and it is being used by
    dozens of parts of a script to transfer data, what happens if both scripts run at the same time and
    use the tempfile? will it throw a text file is busy error or will it patiently wait until a script
    is done using it before it uses it? Because if i send information to the tempfile, then close it,
    then reopen it again to transfer back the information, I don't want the other script to start
    using it in the middle of that sequence or the results will be catastrophic. Any ...
  4. File Format Encyclopedia Release 1.00 - (2)
    File Format Encyclopedia is FREEWARE so you can copy, read, use it freely but you can't modify
    it in any way!!!File Formats Encyclopedia A MUST HAVE for professional programmers!
    Over 300 formats layouts including: graphics,sound, animation, mods, database, text,executables,
    communication and much more ...
  5. Isolating Integers From Characters? - (4)
    Hi there people! I'm new here, so if this post conflicts with any of the laws of this forum
    for any reason, I apologize in advance. I'm trying to write a function that reads from the user
    a set of integers separated by ',' (commas), but I'm having difficulty isolating the
    integers from the characters. I'm not sure if I should do it using a "for" or "while" loop,...
    So if the input is something like: {100,20,50} I should be able to store the integers 100 20 50
    Anybody got any idea how to do that?? I would really appreciate the help!! ...
  6. Removing Characters... - (1)
    From the environment variables, i get the domain of the referring site using SERVER_NAME. The
    includes www. and i have to remove that. I dont believe there is a variable in the environment that
    contains only the domain. So I would need to replace each character in the char* string by "" until
    i hit a '.' then replace the dot with "" and get the remaining string. Here is the catch. I
    can't include big headers because i need the file to stay really small around 20-30kb. So
    ideally, would need to use functions in stdlib.h stdio.h or string.h to get this done. ...
  7. Local File Time To File Time() - (0)
    I'm working on sending some certain data to a server. Part of the process in gathering this data
    is done by using GetLocalTime() to get the current local time, this local time must then be
    converted to a FILETIME structure. I'm trying to get this done properly in Python, however my
    problem is that I do not know what my data will look like when the local time is converted to file
    time. I don't have the necessary compiler on my PC to test the code (for reasons I'm not
    going to waste time explaining, my main PC is temporarily unuseable and I'm using a mu...
  8. Storing Bit Values In A File - (1)
    Hello All, I am developing a utility for zipping and unzipping a file using the Huffman Algorithm.
    The code is implemented using 'C' language. I have finished coding for generating the
    appropriate bit code values for each of the symbols present in file and my next objective is to
    store the bit code values in a seperate file. As you all are aware, the smallest data type that is
    supported by C is the character which is 1 byte. Please can anybody suggest me on how to store the
    bit values generated as codes in a file? Thanks. ...
  9. Running An Extenal File - how to (3)
    hi guyz i fairly new to c++ i started readnig a big book but it gonna take me a while to reach the
    last page and i need to do a menu quite fast so could any one of You help me with this
    /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> : i need to know
    whith action will run an external file using the the app assigned to it in the windows shell (sort
    of like the "run" command in used in dos) or a brief source code with a button fireing some file to
    use as a tutorial /rolleyes.gif" style="vertical-align:middle" emoid=":rolleyes:"...



Looking for weird, characters, appending, file

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for weird, characters, appending, file

*MORE FROM TRAP17.COM*
advertisement



Weird Characters Appending To File



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE