Thread: unusual behaviour by GETS function

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Feb 2008
    Posts
    21

    Unhappy unusual behaviour by GETS function

    The first gets function gets skiped but the remaining get functions work, that is the control just moves on to the next line. WHy is this happenning


    Code:
    void add_address(void)
    {
        int slot;
        slot = -1;
        
        slot = find_free();
        
        if( slot == -1 )
        {
            printf("\nData base full!!!! Cannot add record");
            return;
        }
        
        printf("\nAdding record to database at slot number : %d \n", slot);
        
        printf("\nEnter Name : ");
        gets(address[slot].name);               //<=THIS gets() gets skiped
        
        printf("\nEnter Street : ");
        gets(address[slot].street);              //BUT this gets() works, why???
        
        printf("\nEnter Citi : ");
        gets(address[slot].citi);
        
        printf("\nEnter state : ");
        gets(address[slot].state);
        
        printf("\nEnter ZIP : ");
        scanf("%u", &address[slot].zip);
        
        return;
        
    }
    When I run this program this part of the code
    Code:
        printf("\nEnter Name : ");
        gets(address[slot].name);
    gets neglected, control just moves on to the nex line and asks for the input for the next data which is
    Code:
        printf("\nEnter Street : ");
        gets(address[slot].street);
    I cannot understand why its not asking for a input for
    Code:
        printf("\nEnter Name : ");
        gets(address[slot].name);
    , why is it moving on to next line.

    If I replace "gets" with "scanf", then the compiler asks for the input of name but will skip the next gets function.
    Last edited by capvirgo; 02-07-2008 at 02:10 AM.

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. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Change this program so it uses function??
    By stormfront in forum C Programming
    Replies: 8
    Last Post: 11-01-2005, 08:55 AM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM