0
int main()
{
char c1, c2;
printf("Enter a character: ");
scanf("%c", &c1);
printf("Enter another character: ");
scanf("%c", &c2);

system("pause");
return;
}

Thats what my code looks like, the problem is the code skips the part where it lets you input c2. I dont understand why its doing this. It prints Enter another character: but doesnt take an input. any ideas?

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by gerard4143
0

I modified your code somewhat to display the intial/final values of c1/c2....What do you notice?

#include <stdio.h>

int main()
{
	char c1 = 0, c2 = 0;
	
	fprintf(stdout, "our initial values c1->%d, c2->%d\n", c1, c2);

	printf("Enter a character: ");
	scanf("%c", &c1);
	printf("Enter another character: ");
	scanf("%c", &c2);

	fprintf(stdout, "\nour final values c1->%d, c2->%d\n", c1, c2);

	return 0;
}
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.