about function "fgets"

This is a discussion on about function "fgets" within the C Programming forums, part of the General Programming Boards category; Hi everyone, I was working on alittle program, the program reads from a file and writes to another file by ...

  1. #1
    Registered User
    Join Date
    Apr 2002

    about function "fgets"

    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

    #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 */
              p_box( str1, str2 );  

    thanks in advance

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Waterloo, Texas
    My guess is it is happening inside the p_box function.

    BTW: with fgets you can do:

    fgets(str1, max, infile);

    ...since it will be sure to stop at the appropriate point...
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
        return std::pow
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Yet again we have feof() misunderstanding, and yet again....

    while( fgets(str1,max,infile) != NULL ) {
        p_box( str1, str2 );  

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 01:28 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 06:05 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21