我试图在我的主要方法中扫描一个字符,我的程序只是打印并退出
I am trying to scan a char in my main method and my program just prints and exits
我正在尝试扫描,但我的方法只是打印并退出。它不会扫描。
int main() {
char *one = (char*)malloc(34* sizeof(char));
char *two = (char*)malloc(16* sizeof(char));
char test ;
printf("please enter a Q \n");
scanf("%c", test);
printf("%c\n", test);
return 0;
}
scanf("%c", test);
应该是:
scanf("%c", &test);
我正在尝试扫描,但我的方法只是打印并退出。它不会扫描。
int main() {
char *one = (char*)malloc(34* sizeof(char));
char *two = (char*)malloc(16* sizeof(char));
char test ;
printf("please enter a Q \n");
scanf("%c", test);
printf("%c\n", test);
return 0;
}
scanf("%c", test);
应该是:
scanf("%c", &test);