C code crashes (no idea why) -
basically i'm beginner coder , wrote:
#include <stdio.h> #include <stdlib.h> int main() { system("color 0a"); char playername[13]; char playergender; int playerage; printf("please input name , age!\nname: "); scanf("%s", playername); printf("age (from 18 50): "); scanf("%d", &playerage); label: if(playerage > 18 && playerage < 50) { printf("what gender you, m(male) or f(female): "); scanf("%c", playergender); gender: if(playergender == 'm' || playergender == 'f'){ printf("okay, name %s, you're %d years old , you're %s.", playername, playerage, playergender); }else{ printf("try again.\n\n" "what gender you, m(male) or f(female): "); scanf("%c", playergender); goto gender; } }else{ printf("wrong, try again.\n" "age (from 18 50): "); scanf("%d", &playerage); goto label; } return 0; }
when put required age continue, crashes on scanf
playergender
. right after shows me question gender? mistake?
try:
scanf("%c", &playergender);
instead of
scanf("%c", playergender);
as scanf takes pointer , not reference variable trying fill.
Comments
Post a Comment