gpt4 book ai didi

c - C中的编译器错误,: Expected Expression错误

转载 作者:行者123 更新时间:2023-12-02 10:56:26 26 4
gpt4 key购买 nike

我遇到了一个我真的不知道如何解决的问题。我主要使用Python编写代码,这是我的第一个C语言程序。

#include <stdio.h>

int ask(void) {
scanf("Var");
return 0;
}

int count(ask) {
scanf("number1");
return 0;
}

int main(void) {
printf("This is my first program!\n");
printf("I hope this program turns out well.");
printf("I don't really know what to do, but i think im progressing.\n");
printf("But yeah, This is my first program.\n");
printf("Type an Number");
ask();
count(ask());
printf("Thanks!");
printf(%count%);
return 0;
}
但是,我不断收到错误消息。
main.c:22:10: error: expected expression
printf(%count%);
^
main.c:22:17: error: expected expression
printf(%count%);
^
2 errors generated.
compiler exit status 1
我想要它做的是,用户键入一个数字,然后打印出该数字。虽然还不完整。我希望它写数字1-用户输入,当数字正确时,它会打印“您的数字是:”(数字)

最佳答案

问题(正如已经指出的那样)是您实际上并没有从scanf()调用中获取和存储值。此外,printf(%count%)不是有效的C语法。您需要使用printf("%d", count)
将所有内容放在一起:

#include <stdio.h>

int ask(void) {
int input_number;
scanf("%d", &input_number);
getchar(); # This is so that the '\n' in is read when you hit Enter
return input_number;
}

int main(void) {
printf("This is my first program!\n");
printf("I hope this program turns out well.");
printf("I don't really know what to do, but i think im progressing.\n");
printf("But yeah, This is my first program.\n");
printf("Type an Number");
int input_number = ask();
printf("Thanks!");
printf("The number you entered is %d\n", input_number);
return 0;
}
为了避免犯这样的错误,需要阅读一些内容: printf教程: https://www.tutorialspoint.com/c_standard_library/c_function_printf.htm scanf教程: https://www.tutorialspoint.com/c_standard_library/c_function_scanf.htm

关于c - C中的编译器错误,: Expected Expression错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62489648/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com