Hi everyone,
I was working on alittle program, the program reads
from a file and writes to another file by using the C library funtions
fgets and fputs , the program reads well but when it outputs to the file it writes the message twice instead of only onne time can anyone tell me what I am getting wrong looking at the code below, I just cut some code to show what I have implemented...this is part of the code after the decleration I opend the file and then start processing.
infile message is "helo" it writes twice to outfile
Code:
code
#define max 1024
char* p_box (char* orig_msg , char* msg_after_pbox ) ;
int main (int argc, char *argv[])
{
FILE *infile, *outfile;
//char ch;
char str1 [max];
char str2 [max]; /* temporary for output */
while(!feof(infile))
{
fgets(str1,max-1,infile);
p_box( str1, str2 );
fputs(str2,outfile);
}
fclose(outfile);
fclose(infile);
}
thanks in advance