Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to enter multiple printfs but i dont get opportunity to enter. I can enter only 1, but after that it just ends the programme.I tried with do while but it didnt work

int main()
{
  int number;
  char username[30]="";
  char fullName[30]="";
  char password[30]="";
  printf("Do you want to log in(1) or register (2)? 
");  
  scanf("%d",&number);
  if (number==2)
  {
    printf("username : ");
    scanf("%s",&username);
    printf("Full name : ");
    scanf("%s",&fullName);
    printf("Password : ");
    scanf("%s",&password);
    printf("Repeat password : ");
    scanf("%s",&password);
  }
  return 0;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
232 views
Welcome To Ask or Share your Answers For Others

1 Answer

Read full lines using fgets() into a suitably large buffer, then parse that.

Note that %s will stop at the first blank character, so a full name of "Mr X" will leave "X" in the input buffer, grabbing that for the password and so on. It's really not a robust way of getting input.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...