fputs help

This is a discussion on fputs help within the C Programming forums, part of the General Programming Boards category; Hi all. The just of my program is that it catches a SIGINT signal and then writes something to a ...

  1. #1
    Registered User
    Join Date
    Feb 2004
    Posts
    1

    fputs help

    Hi all. The just of my program is that it catches a SIGINT signal and then writes something to a file. It writes it to the file the first time ok, but the second time it doesn't write. i even tried to fflush it and it still gives me the same problem.

    here's a snipper of my code.
    Code:
    printf("Record Created\n");
          strcat(inputName," | ");
          strcat(address, " | ");
          strcat(phone, " | ");
    printf("%s\n",inputName);
    printf("%s\n",address);
    printf("%s\n",phone);
          fflush(in);
          fputs(inputName,in);
          fputs(address,in);
          fputs(phone,in);
          close(fildes[0]);
          write(fildes[1],"New Record",30);
          write(fildes[1],inputName,30);
          write(fildes[1],"Record Created",30);
          //close(fildes[1]);
          fflush(in);
    Could someone give me some suggestions on how to go about fixing it? Thanks!
    Last edited by Dai-Lo; 02-27-2004 at 05:54 PM.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
     fflush(in);
    I'll assume in is an input stream. As such, you can not flush input streams, only output. Flushing input streams is undefined behaviour.

    It's odd that you call it 'in', if it is actually output. You'll definately want to rename that, because it makes your code unreadable and annoying to debug.

    Otherwise, you'll have to post more code, so I don't have to play guessing games as to what all of your variables are.

    A SIGINT is an interrupt, or rather, it usually means someone's entered an interrupt key on a terminal.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    c99
    c99 is offline
    Registered User
    Join Date
    Feb 2004
    Posts
    79
    Dai-Lo.

    You mention the problem is with signal handling yet you've not
    shown how you handle the signal.

    At a guess, do you reset the signal handler after the first interrupt.
    R.I.P C89

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. fputs only write first part of string
    By jamie85 in forum C Programming
    Replies: 4
    Last Post: 11-17-2005, 08:18 AM
  2. Question about fputs
    By nizbit in forum C Programming
    Replies: 6
    Last Post: 03-03-2005, 07:19 PM
  3. fputs
    By barim in forum C Programming
    Replies: 6
    Last Post: 07-31-2004, 03:41 AM
  4. fputs and fprintf
    By fosca in forum Linux Programming
    Replies: 2
    Last Post: 12-17-2001, 07:15 AM
  5. fputs and sequential file
    By sballew in forum C Programming
    Replies: 5
    Last Post: 11-11-2001, 04:48 PM

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