我正在将此示例代码复制并粘贴到CS50 IDE中,
文件名test.c:
~/workspace/pset1/ $ make test
clang -fsanitize=integer -fsanitize=undefined -ggdb3 -O0 -std=c11 -Wall -Werror -Wextra -Wno-sign-compare -Wshadow test.c -lcrypt -lcs50 -lm -o test
test.c:4:1: error: expected identifier or '('
for (int i = 0; i < 10, i++)
我在尝试编译时遇到以下错误:
:setmyvar
set /P myvariable=
if /i %myvariable%==<anything containing one or more "> goto bad
goto success
:bad
echo Variable cannot contain quotation marks.
pause
goto setmyvar
:success
echo Success!
^ 生成1个错误。 make:*** [test]错误1
我看了,我发现的所有答案都包含语法错误,但在点击此墙后我一直在复制/粘贴示例代码。
答案 0 :(得分:0)
如果那是您的整个文件,我认为您会发现代码必须包含某些描述的功能,可能是main
:
#include <stdio.h>
int main (void) {
for (int i = 0; i < 10; i++) {
printf ("test this\n");
}
return 0;
}
你会看到我做过的其他一些改变应该让它变得更好&#34;:
for
循环。答案 1 :(得分:0)
谢谢 - 我需要在函数中包含循环,并在循环本身中出现语法错误(逗号而不是半冒号)。
答案 2 :(得分:0)
如前所述,C语法在for循环中需要使用分号。你应该是:
for(int i = 0; i&lt; 10; i ++)
答案 3 :(得分:0)
在这样的for循环中,您需要使用分号而不是逗号。我必须是这样:
#include <cs50.h>
#include <stdio.h>
for (int i = 0; i < 10; i++)
{
printf("test this");
}
不是这样的:
#include <cs50.h>
#include <stdio.h>
for (int i = 0; i < 10, i++)
{
printf("test this");
}
如您所见,您必须在分号后使用分号而不是逗号
i < 10
部分。