Gets problem I think

This is a discussion on Gets problem I think within the C Programming forums, part of the General Programming Boards category; How can I make that the do-while keeps repeating while the user hasnt entered anything?? I mean, if when asked ...

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    75

    Gets problem I think

    How can I make that the do-while keeps repeating while the user hasnt entered anything?? I mean, if when asked to enter your name you just press ENTER then the do-while repeats... I have this code but it doesnt work!!

    Can you help me?

    Code:
    void pidenombre(void)
    {
      do{
        printf("Your name?");
        gets(nombre);
      }while(nombre=="\0");
    }
    ---Programming is like roaming, you never know where you'll end at------

    If 'here' is pronounced as 'hear', why 'there' isnt pronounced as 'dear'??

    paninaro3000@yahoo.com

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You should be trying to capture a new line not a null terminator. so use '\n' instead of '\0'.

  3. #3
    Im back! shaik786's Avatar
    Join Date
    Jun 2002
    Location
    Bangalore, India
    Posts
    345
    >
    }while(nombre=="\0");

    Is wrong. You are trying to compare strings but instead are comparing their addresses. Try this instead:
    Code:
    }while(nombre[0]=='\0'); /*   Check the single quote '   */
    OR
    Code:
    }while(!strlen(nombre));
    >You should be trying to capture a new line not a null terminator. so use '\n' instead of '\0'.
    gets() breaks when it encounters a '\n', which is not returned in the string, so, checking for '\n' is not going to help you
    Last edited by shaik786; 07-01-2002 at 03:48 AM.

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You all have overlooked the most obvious flaw: they're actually using gets! Never use gets. Use fgets instead. It's safer.

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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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