c - 删除C中变量的内容

标签 c

我想在 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/

相关文章:

c - 在数组中搜索字符串

c - OpenMP 并行错误 : missing increment expression

c - 如何恢复被覆盖的文件?

c - 每当我编译程序时,我都无法运行 gcc 为我创建的文件

c - 转到 VLA 范围

c - 线程安全与可重入

C - 重新分配无效的下一个大小的字符串

币种找零,以特定币种的类型作为返回值

c - 如何从流中一次读取n个字符的字符串?

c - strtok crash 不知道为什么会被窃听