Thread: crazy output

  1. #16
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Prelude, I've always been pretty confused about buffers. From
    >your reply, I gather that characters only leave the buffer when
    >scanf is successful, otherwise they just stay there?
    Correct, if scanf fails then whatever is not read will remain in the stream.

    >I've noticed that you are one of the main moderators here and
    >you seem to really know your stuff. Do you do this while you're
    >programming?
    Well, I'm not a moderator but I do spend a lot of time here. I'm usually around during the day when I'm at work and nothing is going on ( which is often ).

    -Prelude
    My best code is written with the delete key.

  2. #17
    Unregistered
    Guest
    Prelude, is there much demand for C programmers right now? I'm kind of looking for my first programming job. I took a hardware course that included two C classes and then learned the C portion of Deitel.

  3. #18
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >is there much demand for C programmers right now?
    Right now the pickings are very slim and entry level positions are all but nonexistant. This should change soon, but it's impossible to guess when.

    -Prelude
    My best code is written with the delete key.

  4. #19
    Unregistered
    Guest
    Prelude, do you find that the board is a good way to keep your skills sharp? Or is it more of a pastime?

  5. #20
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Prelude, do you find that the board is a good way to keep your
    >skills sharp? Or is it more of a pastime?
    For the most part it's a passtime, but every once and a while a question pops up that requires me to double check myself or do research to find the answer. And "find the error" questions are useful for keeping my debugging skills sharp since you see some strange errors around here.

    -Prelude
    My best code is written with the delete key.

  6. #21
    Unregistered
    Guest
    Prelude, just wanted to thank you for your insights, and will be talking to you again on some other threads!

  7. #22
    Registered User
    Join Date
    Dec 2001
    Posts
    27

    scanf

    Hi,

    Below is a way around the scanf problem. Maybe not the best but it works in both of my 16bit compilers and the free Borland 5.5.

    #include<stdio.h>
    #include <conio.h>

    int main()
    {
    char errorbuff[100]; //Really doesn't have to be this large.?
    int numberin;
    int correctflag; // Set when a int is entered

    for(correctflag = 0; correctflag == 0; )
    {
    printf("\nEnter A Number ");

    if(!scanf("%d",&numberin)) // the entry was not an int.
    {
    scanf("%s",errorbuff);
    }
    else
    {
    correctflag = 1;
    }
    }
    printf("\nNumber entered %d",numberin);
    getch();
    return 0;
    }
    Just another way.
    Hope it helps.
    Last edited by Pappy1942; 04-09-2002 at 10:31 AM.
    Pappy
    You learn something new everyday.

  8. #23
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >if(!scanf("%d",&numberin)) // the entry was not an int.
    >{
    >scanf("%s",errorbuff);
    >}
    >else
    >{
    >correctflag = 1;
    >}
    Eight lines just do handle a bug with scanf?

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help for my output array
    By qwertysingh in forum C Programming
    Replies: 1
    Last Post: 02-17-2009, 03:08 PM
  2. execl()/fork() output
    By tadams in forum C Programming
    Replies: 19
    Last Post: 02-04-2009, 03:29 PM
  3. Digital Logic + trees=getting crazy! :)
    By smoking81 in forum C Programming
    Replies: 8
    Last Post: 09-11-2008, 07:49 AM
  4. Replies: 4
    Last Post: 11-30-2005, 04:44 PM
  5. Formatting output into even columns?
    By Uncle Rico in forum C Programming
    Replies: 2
    Last Post: 08-16-2005, 05:10 PM