Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

larswik

macrumors 68000
Original poster
Sep 8, 2006
1,552
11
Had a quick question. I am writing a small bit of code to help do some math for a game we play. I first have it ask for a number and then ask for a letter. When I tested the first part of this code it hangs in the console and won't move to the next question.

Code:
#include <stdio.h>

int main (int argc, const char * argv[]) {
	int level;
	char crit;
	
	printf("Enter the level of the Character:");
	scanf( "%d\n", &level );
	
	printf("Enter the Crit letter:");
	scanf( "%c", &crit );
	
    return 0;
}

I am t a loss to understand why it won't print the second printf line. It seems so simple? The code is not finished yet but this little part should work even though the code is not completed yet I wold think.

Thanks

-Lars
 
1. Get rid of the newline in the first call to scanf().

2. Understand the behavior of %c in scanf().
 
1. Get rid of the newline in the first call to scanf().

2. Understand the behavior of %c in scanf().

0. Understand the role of whitespace (which includes newlines) in scanf patterns. Recommended minimum: Read The Fine Man Page (RTFMP).
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.