我想在 int 变量到达 else 语句时删除它的内容。
程序使用 scanf 请求 1 到 5 之间的数字,该数字存储在 int 变量中,如果该数字不在 1 到 5 之间,则用户将被定向到 else 语句,而我使用了 goto 语句回到开头,我想知道如何在 else 语句中删除变量的内容,这样我就不会创建连续循环。
对于 getchar 来说,它是 fpurge(stdin)。我运行的是 Mac OS X。
下面是代码:
#include <stdio.h>
int main (int argc, const char * argv[])
{
int code;
start:
puts("Please type your error code.");
puts("Range 1-5: ");
scanf("%d", &code);
switch(code)
{
case 1:
printf("INFORMATION\n");
case 2:
printf("INFORMATION\n");
case 3:
printf("INFORMATION\n");
case 4:
printf("INFORMATION\n");
case 5:
printf("INFORMATION\n");
default:
printf("INFORMATION\n");
goto start;
}
}
最佳答案
只需将 int 值设置为其他值,例如:
theValue = 0;
关于c - 删除C中变量的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5036441/