Skip to content

Instantly share code, notes, and snippets.

@jadia
Last active January 17, 2019 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadia/290f33cc8ab16d45b22875259259df7d to your computer and use it in GitHub Desktop.
Save jadia/290f33cc8ab16d45b22875259259df7d to your computer and use it in GitHub Desktop.
Yes/No option in C program

I had the following code and the yes no functionality won't work.

printf("\nDo you wish to add more records? [y/n] ");
		scanf("%c", &choice);
		printf("\nYour choice: %c\n", choice);
		if (choice != 'y')
		{
			printf("Making choice false.");
			addMore = false;
		}

So, according to stackoverflow answer, just adding a space in scanf will solve the problem.

scanf(" %c", &choice);  
       ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment