简体   繁体   English

如何修复 C 中的 switch 语句中的错误?

[英]How to fix error in switch statement in C?

I am coding in sandbox.cs50.io and I am persistently getting the same error.我在 sandbox.cs50.io 中编码,并且一直遇到同样的错误。 This is my code:这是我的代码:

#include <stdio.h>

#include <cs50.h>


int main(void)

{

int x = get_int( );

switch(x)

    {

    case1: printf("One!\n");

           break; 

    case2: printf("Two!\n");

           break; 

    case3: printf("Three!\n");

           break;

    default: printf("Sorry!\n");

    break;

    }

}

THE ERROR:错误:

clang -fsanitize=signed-integer-overflow -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wno-unused-parameter

 -Wno-unused-variable -Wshadow    switch.c  -lcrypt -lcs50 -lm -o switch

switch.c:6:18: **error: too few arguments to function call, at least argument 'format' must be specified**

**int x = get_int( );**

        ~~~~~~~  ^

/usr/include/cs50.h:82:1: note: 'get_int' declared here

int get_int(const char *format, ...) __attribute__((format(printf, 1, 2)));

^

1 error generated.

<builtin>: recipe for target 'switch' failed

make: *** [switch] Error 1

You need a format string: x = get_int("%d");您需要一个格式字符串: x = get_int("%d");

You have entered case1, case2 and case3.您已输入 case1、case2 和 case3。 They should be case 1, case 2, case 3, with a space I mean.它们应该是案例 1、案例 2、案例 3,我的意思是一个空格。 Try it.试试看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM