Trying programming with C, Getting Expected x before Y type error
尝试使用C(自学和使用《新波士顿指南》),但尝试简单地问这些问题,然后如果答案匹配,则打印X或Y。
我已经注释掉yourAge,因为我在做什么,我不需要它,如果您删除if语句并仅将其打印为Hi,firstName,则它可以工作,我可以看到您是yourAge等。
我遇到的错误是:
||=== Build: Debug in TestProject (compiler: GNU GCC Compiler) ===|
C:\\Users\\admin-jb\\Desktop\\TestCProject\\TestProject\\main.c||In function 'main':|
C:\\Users\\admin-jb\\Desktop\\TestCProject\\TestProject\\main.c|21|warning: implicit declaration of function 'If' [-Wimplicit-function-declaration]|
C:\\Users\\admin-jb\\Desktop\\TestCProject\\TestProject\\main.c|22|error: expected ';' before '{' token|
C:\\Users\\admin-jb\\Desktop\\TestCProject\\TestProject\\main.c|33|warning: control reaches end of non-void function [-Wreturn-type]|
||=== Build failed: 1 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===|
使用代码::块13.12
有什么想法吗?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char firstName[20]; // int yourAge; char excelLike[20]; printf("Please Enter Your Name?\ "); scanf("%s", firstName); // printf("How old are you?\ "); // scanf("%d", &yourAge); printf("Do you like Excel?\ "); scanf("%s", excelLike); If(strcmp(excelLike,"yes") == 0) { printf("Hey, %s I love Excel too!!\ ", firstName); } else { printf("Hey %s, pfft nor do I, its rubbish!\ ", firstName); } return 0; } |
1 | C:\\Users\\admin-jb\\Desktop\\TestCProject\\TestProject\\main.c|21|warning: implicit declaration of function 'If' [-Wimplicit-function-declaration]| |
您使用的是
相关:根据
The above tokens (case sensitive) are reserved (in translation phases 7 and 8) for use as keywords, and shall not be used otherwise.....
根据您的用法,编译器无法将关键字
说,
您应将输入字符串的长度限制为
1 |