Thread: re-enter the info.

  1. #1
    Registered User
    Join Date
    Jul 2002
    Posts
    13

    re-enter the info.

    I write the code to ask the user to enter some information like below:

    Enter your name: Kewill
    Enter your age: 20

    After the user entered his/her name and age, he/she realise that he/she entered the wrong name.

    My question is how to move the cursor back to "Enter your name: " and allow the user delete the wrong name and re-enter again.

  2. #2
    Registered User
    Join Date
    Aug 2001
    Posts
    247
    you could use a combination of gotoxy(); and clrscr(); in <conio.h>
    but this is compiler specific, check compiler help files for details.
    hoping to be certified (programming in c)
    here's the news - I'm officially certified.

  3. #3
    Registered User
    Join Date
    Jul 2002
    Posts
    28
    Here's a real simple version of how to do this.
    Hope it helps.

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <conio.h>
    
    int main(void)
    {
     char ans='\0';
     char name[BUFSIZ];
     char age[BUFSIZ];
     char input[BUFSIZ];
    
     do
     {
      clrscr();
      puts("");
      // get the name
      printf(" Enter your name:");
      if(fgets(input,BUFSIZ,stdin)!=NULL)
      {
       sscanf(input, "%s", name);
      }
    
      // get the age
      printf(" Enter your age:");
      if(fgets(input,BUFSIZ,stdin)!=NULL)
      {
       sscanf(input, "%s", age);
      }
    
      printf("\n name is %s", name);
      printf("\n age is %s\n", age);
      printf("\n type y if this is correct,  n if wrong <>");
    
      if(fgets(input,BUFSIZ,stdin)!=NULL)
      {
       sscanf(input, "%c", &ans);
      }
     } while(ans!='y');
    
     return EXIT_SUCCESS;
    } // end int main(void)

  4. #4
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231

    Re: re-enter the info.

    Originally posted by kewell
    I write the code to ask the user to enter some information like below:

    Enter your name: Kewill
    Enter your age: 20

    After the user entered his/her name and age, he/she realise that he/she entered the wrong name.

    My question is how to move the cursor back to "Enter your name: " and allow the user delete the wrong name and re-enter again.
    Show us some code... then we can guide you better.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need Help With a BlackJack Program in C
    By Jp2009 in forum C Programming
    Replies: 15
    Last Post: 03-30-2009, 10:06 AM
  2. Assignment output help
    By Taka in forum C Programming
    Replies: 13
    Last Post: 09-23-2006, 11:40 PM
  3. Input for Struct?
    By stewade in forum C Programming
    Replies: 26
    Last Post: 05-03-2004, 11:52 AM
  4. hi need help with credit limit program
    By vaio256 in forum C++ Programming
    Replies: 4
    Last Post: 04-01-2003, 12:23 AM
  5. I need help badly
    By taz_jiggy in forum C++ Programming
    Replies: 4
    Last Post: 04-23-2002, 09:36 PM