Character comparison in C? -


when pass in 1 of characters specified, returns 2 if incorrect character? comparing these incorrectly?

int valid_character(char character) {     if (character == '*' || character == '%' || character == '#') {         return 1;     } else {         return 2;     } } 

edit:

the problem calling function:

if (selection == 1) {     printf("enter character, width , length: ");     scanf("%c %d %d", &c, &width, &length);     putchar(c);     int response = valid_character(c);     if (response == 1) {         draw_rectangle(width, length, c);     } else {         printf("%d", response);         printf("invalid data provided.");     } } 

when call putchar(c); prints out 1 though passing in % why this?

you did not post whole function! had scanf before code fragment left pending \n in input stream.

as found out yourself, can skip \n , other white space reading character with:

scanf(" %c%d%d", &c, &width, &length); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -