为什么在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 ×1