小编Dr *_*pec的帖子

在scanf()中格式化字符串和字符转换之前,程序退出时没有空格

为什么在scanf()程序中的格式说明符之前使用空格时工作正常呢?代码如下:

printf("What's your username: ");
scanf(" %s", username);

printf("Do you want to make a deposit or a withdrawal? [d/w]\n");
scanf(" %c", &choice);
Run Code Online (Sandbox Code Playgroud)

当我没有像下面这个代码的空格时,它会退出:

printf("What's your username: ");
scanf("%s", username);

printf("Do you want to make a deposit or a withdrawal? [d/w]\n");
scanf("%c", &choice);
Run Code Online (Sandbox Code Playgroud)

对此有一个很好的解释吗?

c

0
推荐指数
1
解决办法
42
查看次数

标签 统计

c ×1