Thread: Program skips fegts function - HELP

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    7

    Program skips fegts function - HELP

    I'm writing a program that needs string input into a struct, but for some reason it is being skipped over.

    Here's the bulk of the code.

    Code:
    struct ConfigInfo
    {
       char VendorName[20];
       char Description[200];
       int NumKeys;
       int NumLicenses[10];
       int NumMemos[10];
       char Expiry[10];
    };
    
    .
    .
    .
    
    
       struct ConfigInfo *temp;
       temp=malloc(sizeof(struct ConfigInfo));
    
       printf("\nEnter the Vendor Name: ");
       fgets(temp->VendorName,20,stdin);
    
       printf("\nEnter the Reason for sending the key: ");
    The ... obviously represented other functions and the function that the code is in. When I run the program, it just prints the two printf statements and gives me no time to input a string. What's wrong? Thanks for any help.

  2. #2
    Registered User
    Join Date
    Dec 2007
    Posts
    2,675
    Probably a leftover newline in the buffer from a previous fgets that you're not showing. Read the FAQ entry for info on using getchar() to prevent this behavior.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by rags_to_riches View Post
    Probably a leftover newline in the buffer from a previous fgets that you're not showing. Read the FAQ entry for info on using getchar() to prevent this behavior.
    fgets() doesn't leave anything in the buffer, but (f)scanf does - otherwise the solution is correct.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    Registered User
    Join Date
    Jul 2008
    Posts
    7
    Quote Originally Posted by rags_to_riches View Post
    Probably a leftover newline in the buffer from a previous fgets that you're not showing. Read the FAQ entry for info on using getchar() to prevent this behavior.
    Thanks a lot for your help. And sorry about misspelling the thread title, just noticed it :/

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. prime number program with function
    By mackieinva in forum C Programming
    Replies: 17
    Last Post: 09-20-2007, 08:36 AM
  3. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  4. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM
  5. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM