搜档网
当前位置:搜档网 › C语言中各个错误的意思

C语言中各个错误的意思

字体颜色:<序号> 淡紫色 ;

Error(编译错误) 红色;

“%d”(设计错误) 红色;

“;” (修改) 绿色;

<1>在scanf函数里多写了\n,容易出现无法继续运行,按下 " . "符号后强制运行的后果。

Eg: scanf("%d \n",&piarr[i][j]); 此句就存在这种问题。

在C语言里scanf函数是不需要输入\n就可以自动换行。

正确: scanf("%d",&piarr[i][j]);

在scanf函数里空格多了容易出现此类问题。

Eg: scanf(" %d " , &score); 空格比较多。

正确: scanf(“%d”);



<2>“F:\C语言\CH-6\例程6-18.cpp:19: error: invalid operands of types `const char[3]' and `int' to binary `operator&'”表示你所输入的语句存在缺少“ , ”的问题.

Eg:scanf(" %d " &n2); 在”后缺少“ , ”

正确: scanf("%d", &n2);



<3> “ F:\C语言\CH-4\例程4-4.cpp: In function `int main()':

F:\C语言\CH-4\例程4-4.cpp:8: error: expected `;' before "scanf"”

表示你上一行代码忘记了输入“ ; ”。

Eg: printf("请输入一个数字:") ←此处就存在此问题

scanf("%d" , &number);

正确:printf("请输入一个数字:"); ←此处添加“;”。

scanf("%d" , &number);



<4> 格式化字符用错,容易导致未知的问题出现。

“char select;

printf("请选择你要去的地方:\n(A) 三亚\n(B) 海口\n(C) 万宁\n");

scanf("%d" , &select); ←此处格式化字符符号错误

switch(select)

{

case 'a':

case 'A':

puts("三亚三日游");

break;

case 'b':

case 'B':

puts("海口四日游");

break;

case 'c':

case 'C':

puts("万宁五日游");

break;

defaut:

printf("选项错误");”

正确:scanf("%c" , &select); 此处为字符格式化。



<5>“F:\C语言\CH-7\例程7-2.cpp:15: error: expected `)' before ';' token”看到这样的错误提示,你就要仔细检查你的代码了。

看看是不是少输入了“)”这个。

Eg: printf("%d的%d次方为:%d",x,y,fun(x,y); 这里少了“)

正确:printf("%d的%d次方为:%d",x,y,fun(x,y));

<6>有时候会出现一种编译正常但是结果却不正常的现象。

比如下列代码:

int fun(int a,int b) /*定义fun函数 */

{

int i;

int sum; 此处未声明sum 的初始值

for(i=0;i
{

sum=sum*a;

}

return sum;

}

这是一个自定义函数的定义内容。

显示的结果却总是错的!!!!

int sum; 在程序中未给sum 设置初始值。

正确:

int fun(int a,int b) /

*定义fun函数 */

{

int i;

int sum=1; 此处声明sum 的初始值

for(i=0;i
{

sum=sum*a;

}

return sum;

}

<7> “ F:\C语言\CH-7\例程7-6.cpp:7: error: expected `,' or `...' before "int" ” 错误提示的问题是在int之前缺少“ ,或 ---”。

Eg: void mix(int x int* y); 这里就缺少“ ,”

正确:void mix(int x ,int* y);

<8>有时候你会在编译的时候(指针)出现以下错误提示:

“D:\ProgramFiles\DEV-CPP\Lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'”

检查 int main()是否输入错误



<9>”F:\Có???\CH-7\ày3ì7-10.cpp:25: error: `put' undeclared (first use this function)

F:\Có???`CH-7\ày3ì7-10.cpp:25: error: (Each undeclared identifier is reported only once for each function it appears in.)”

你的字母输错啦!仔细看看有“put”这个函数么,应该是“puts”吧??

Eg: void print_word1 (char* str)

{

put ("?aê?print_word1oˉêy"); 这里的put不对

put ("str");

}

正确:

void print_word1 (char* str)

{

puts("?aê?print_word1oˉêy");

puts("str"); 正确的“put”.

}



<10> 在编译函数指针数组时出现以下问题:

” F:\C语言\CH-7\例程7-12.cpp:7: error: expected identifier before ')' token

F:\C语言\CH-7\例程7-12.cpp:7: error: ISO C++ forbids declaration of `parameter' with no type

F:\C语言\CH-7\例程7-12.cpp:7: error: invalid conversion from `int (*)(int, int)' to `int (*)(int, int, int)'”



<11> 编译提示以下错误:

D:\ProgramFiles\DEV-CPP\Lib/libmingw32.a(main.o)(.text+0x106):main.c: undefined reference to `WinMain@16'

仔细检查主函数main()输入是否错误。



<12>在局部变量中声明的时候,容易犯习惯性的定义问题。

Eg: void foo (void)

{

x=50; /*声明局部变量X 一定要注意是声明 */

printf("局部变量X=%d\n",x);

}

正确:

void foo (void)

{

int x=50; /*声明局部变量X 一定要注意是声明 */

printf("局部变量X=%d\n",x);

}

<13>” F:\C语言\CH-7\例程7-18.cpp:21:16: warning: unknown escape sequence: '\276'”





<14>” E:\Có???\CH-8\ 8-1.cpp:25: error: `system' undeclared (first use this function)

E:\Có???\CH-8\ 8-1.cpp:25: error: (Each undeclared identifier is reported only once for each function it appears in.)”





<15>” E:\C语言\CH-8\例程8-5.cpp:26: error: `(((void)r1, (void)r2), h)' cannot be used as a function

E:\C语言\CH-8\例程8-5.cpp:26: error: `2' cannot be used as a function

E:\C语言\CH-8\例程8-5.cpp:28: error: `(((void)r1, (void)r2), h)' cannot be used as a function

E:\C语言\CH-8\例程8-5.cpp:28: error: `2' cannot be used as a function”

不知道为什么,我重复重新编译后,

错误不在了!

<16>编译正常,但是程序运行中突然弹出

“0x77c12a16指令引用的“0x000000024”内存。该内存不能

为”read”.

仔细检查后发现错误语句:

“printf("https://www.sodocs.net/doc/ce13772326.html, = %s\n",https://www.sodocs.net/doc/ce13772326.html,);

printf("s1.score = %s\n",s1.score);“ 此处应该为d;

修改之后正常。

<17>”E:\Có???\CH-9\ 9-2.cpp:19: error: new types may not be defined in a return type

E:\Có???\CH-9\ 9-2.cpp:19: error: extraneous `int' ignored

E:\Có???\CH-9\ 9-2.cpp:19: error: `main' must return `int'”










#include
#define P n*i=t
void main()
{
int n,i,t;
for(n=1,i=1;n<=9,i<=9;i++);
{
t=n*i;
if(i==9)
n++;
}
putchar (P);
}

相关主题