VC编译C语言出现syntax error : missing ')' before ';'错误
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VC编译C语言出现syntax error : missing ')' before ';'错误相关的知识,希望对你有一定的参考价值。
最近开始学习C语言,照着书本打代码时用VC编译老是出现这个错误,大家帮我看看
#include <stdio.h>
int main()
int chosen = 15;
int guess = 0;
int count = 3;
printf("\n这是一个猜数字游戏This is a guessing game.");
printf("\nI have chosen a number between 1 and 20. which you must guess.\n");
for(; count>0 ; --count;)
printf("\nYou have %d tr%s left.", count, count==1 ? "y" : "ies");
printf("\nEnter a guess:");
scanf("%d", &guess);
if(guess == chosen)
printf("\n You guessed it!\n");
return 0;
if(guess<1 || guess > 20 )
printf("I said between 1 and 20.\n");
else
printf("Sorry. %d is wrong.\n", guess);
printf("\nYou have had three tries and faild. The nember was %d\n",chosen);
return 0;
错误提示为:
D:\presley\C语言例子\[C语言入门经典(第四版)]\chapter4循环\数字猜谜游戏\1.c(12) : error C2143: syntax error : missing ')' before ';'
D:\presley\C语言例子\[C语言入门经典(第四版)]\chapter4循环\数字猜谜游戏\1.c(12) : error C2059: syntax error : ')'
编译成功但是执行总是出现错误
LINK : fatal error LNK1168: cannot open Debug/数字猜谜游戏.exe for writing
Error executing link.exe.
打不开是怎么回事?
详细修改后代码:
#include <stdio.h>int main()
int chosen = 15;
int guess = 0;
int count = 3;
printf("\\n这是一个猜数字游戏This is a guessing game.");
printf("\\nI have chosen a number between 1 and 20. which you must guess.\\n");
for(; count>0 ; --count)
printf("\\nYou have %d tr%s left.", count, count==1 ? "y" : "ies");
printf("\\nEnter a guess:");
scanf("%d", &guess);
if(guess == chosen)
printf("\\n You guessed it!\\n");
return 0;
if(guess<1 || guess > 20 )
printf("I said between 1 and 20.\\n");
else
printf("Sorry. %d is wrong.\\n", guess);
printf("\\nYou have had three tries and faild. The nember was %d\\n",chosen);
return 0;
运行效果:
TES 286
参考技术A “......1.c(12)”的意思就是告你第十二行出错了,然后你数过去,看见哪里有“;”看看这个地方是不是出错了。学程序要会看报的错误是什么。 参考技术B for(; count>0 ; --count;)//后面的count后面多个分号 参考技术C for(; count>0 ; --count;)这里多了个分号,改成
for(; count>0 ; --count)追问
编译成功但是执行总是出现错误
LINK : fatal error LNK1168: cannot open Debug/数字猜谜游戏.exe for writing
Error executing link.exe.
打不开是怎么回事?
Keil C51编译报错error C141: syntax error
错误代码:
1 typedef unsigned char uchar 2 uchar KeyRowColumnScan() 3 { 4 GPIO_KEY = 0x0f; 5 uchar key_value = 0; // 报错行 6 // 省略 7 return key_value; 8 }
错误信息:
key_array.c(44): error C141: syntax error near ‘uchar’
错误原因:
由于Keil、ADS等某些遵循老的C标准的编译器,在函数定义的内部,必须把所有的局部静态变量和自动变量都声明/定义了之后,然后才能开始后续的代码书写,否则编译器会报错,将代码更改如下后,编译正确。
1 typedef unsigned char uchar 2 uchar KeyRowColumnScan() 3 { 4 uchar key_value = 0; // 必须在函数开始出定义所有变量 5 GPIO_KEY = 0x0f; 6 // 省略 7 return key_value; 8 }
以上是关于VC编译C语言出现syntax error : missing ')' before ';'错误的主要内容,如果未能解决你的问题,请参考以下文章
error C2143: syntax error : missi 是啥错误?
C语言问题,error C2143: syntax error : missing ';' before 'type'啥意思?
vc编译中的报错syntax error : 'constant'