帮助:无法编译正确的c程序 [英] Help: a correct c program can not be complied

查看:65
本文介绍了帮助:无法编译正确的c程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

c程序是一个例子,应该是正确的。


我试图用MS studio 6.0编译c文件。但是失败的是

几个错误和警告信息。有谁知道如何使它工作?

谢谢。

这是c文件:

/ *文件名way.c * /

#include< stdio.h>

#include< conio.h>

#include< dos.h>

void put(int x,int y){

textcolor(CYAN);

gotoxy(x,y);

cprintf("。");

声音(440);

延迟(3);

nosound(); < br $>

}


void snd(void){//这只是一个想法;)

声音(100 );

延迟(2);

nosound();

}


void main ()

{

int x = 1,y = 2,ctr = 0;

_setcursortype(_NOCURSOR); //只是为了眼睛舒适;)

clrscr();

gotoxy(1,1);

textcolor(白色);

cprintf(退出ESC,使用arrowkeys来控制); //指令

窗口(1,2,80,25); //设置移动区域

put(x,y); //放笑脸

while(ctr!= 1)

switch(getch()){

//你可以在这里使用kbhit但是我只写了前一个。

案例77://写

if(x> = 1&& x< 79){

gotoxy(x,y);

cprintf("");

x ++;

}

put(x,y);

snd();

break;

case 75:// left

if(x> 1&& x< = 80){

gotoxy(x,y);

cprintf("");

x--;

}

put(x,y);

snd();

休息;

案例72://上涨

if(y <= 25&& y> 2){

gotoxy(x,y);

cprintf("");

y--;

}

put(x,y);

snd();

break;

case 80:// down

if(y <24& y> = 2){

gotoxy(x,y);

cprintf("");

y ++;

}

put(x,y);

snd();

休息;

案例27://退出

ctr = 1;

休息;

}

textcolor(7); //回到正常颜色

返回(0);

}

The c program is an example and should be correct.

I tried to compile the c file with MS studio 6.0. But failed with the
several err and warning messages. Does anyone know how to make it work?
Thanks.
Here is the c file:
/*file name way.c*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
void put (int x,int y) {
textcolor(CYAN);
gotoxy(x,y);
cprintf(".");
sound(440);
delay(3);
nosound();

}

void snd (void){ // it was just an idea ;)
sound(100);
delay(2);
nosound();
}

void main()
{
int x=1,y=2,ctr=0;
_setcursortype(_NOCURSOR); //just for eye comfort ;)
clrscr();
gotoxy(1,1);
textcolor(WHITE);
cprintf("ESC to exit, use arrowkeys to control"); //directive
window(1,2,80,25); // setting moving area
put(x,y); // puting smiling face
while(ctr!=1)
switch(getch()){
//you can use kbhit here but i wrote just ex.
case 77: // write
if(x>=1 && x<79){
gotoxy(x,y);
cprintf(" ");
x++;
}
put(x,y);
snd();
break;
case 75: // left
if(x>1 && x<=80){
gotoxy(x,y);
cprintf(" ");
x--;
}
put(x,y);
snd();
break;
case 72: // up
if(y<=25 && y>2){
gotoxy(x,y);
cprintf(" ");
y--;
}
put(x,y);
snd();
break;
case 80: // down
if (y<24 && y>=2){
gotoxy(x,y);
cprintf(" ");
y++;
}
put(x,y);
snd();
break;
case 27: // quit
ctr=1;
break;
}
textcolor(7); //turn back to normal color
return(0);
}

推荐答案

kim< yj ****** @ hotmail.com>写道:
kim <yj******@hotmail.com> writes:
c程序是一个例子,应该是正确的。

我试图用MS studio 6.0编译c文件。但是失败了几个错误和警告信息。有谁知道如何使它工作?谢谢。


您没有向我们显示错误和警告信息。

这是c文件:
/ *文件名way.c * /
#include< stdio.h>
#include< conio.h>
#include< dos.h>


< conio.h>和< dos.h>是非标准标头。我们不能帮助你在这里遇到你可能遇到的问题。你需要在Windows特定的新闻组中询问



[snip] void main()


main()返回int,而不是void。有些编译器可能会接受void main(),

但是根本没有理由不正确地声明它:


int main(void)


[snip] return(0);
}
The c program is an example and should be correct.

I tried to compile the c file with MS studio 6.0. But failed with the
several err and warning messages. Does anyone know how to make it
work? Thanks.
You didn''t show us the error and warning messages.
Here is the c file:
/*file name way.c*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
<conio.h> and <dos.h> are non-standard headers. We can''t help you
here with an problems you might be having with them; you''ll need to
ask in a Windows-specific newsgroup.

[snip] void main()
main() returns int, not void. Some compilers may accept void main(),
but there''s really no reason at all not to declare it properly:

int main(void)

[snip] return(0);
}




你要从a返回一个值无效功能。如果它是除main()之外的函数

,您可以放弃return语句或

将其更改为return;。但是既然你应该声明main返回

int,那应该解决return语句的任何问题。


你遇到的任何其他问题都是可能是Windows特定的;如果

所以,我们无法帮助你。


-

Keith Thompson(The_Other_Keith) ks *** @ mib.org < http://www.ghoti.net/~kst>

圣地亚哥超级计算机中心< *> < http://users.sdsc.edu/~kst>

我们必须做点什么。这是事情。因此,我们必须这样做。



You''re returning a value from a void function. If it were a function
other than main(), you might either drop the return statement or
change it to "return;". But since you should declare main to return
int anyway, that should fix any problem with the return statement.

Any other problems you''re having are likely to be Windows specific; if
so, we can''t help you with them.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.


kim写道:
kim wrote:
c程序是一个例子,应该是正确的。 />
我试图用MS studio 6.0编译c文件。但是失败了几个错误和警告信息。有谁知道如何使它工作?
谢谢。


首先重播main的非法和文盲返回类型。

取出所有非标准的东西(或者询问你的程序在

特定于Microsoft的新闻组,邮件列表或技术支持)。那个

意味着删除包含< conio.h>,< dos.h>,textcolor(),

gotoxy(),cprintf(),sound()的行,delay(),nosound(),_ setcursortype(),

clrscr(),window()和getch()。剩下的代码如下。它现在

有一个破坏的开关声明。

你也可能修复这些神奇的数字。


#include< stdio。 h>

void put(int x,int y){}


void snd(void){}


int main(void)

{

int x = 1,y = 2,ctr = 0;

put(x,y );

while(ctr!= 1)

开关(/ *需要一个变量* /){

案例77:

if(x> = 1&& x< 79)x ++;

put(x,y);

snd();

休息;

案例75:

if(x> 1&& x< = 80)x--;

休息;

案例72:

if(y <= 25&& y> 2)y--;

break;

case 80:

if(y< 24& y> = 2)y ++;

break;

案例27:

ctr = 1;

休息;

}

返回0 ;

}


[OP'代码] / *文件名way.c * /
#include< stdio.h>
#include< conio.h>
#inclu de< dos.h>
void put(int x,int y){
textcolor(CYAN);
gotoxy(x,y);
cprintf("。 ");
声音(440);
延迟(3);
nosound();

}

void snd( void){//这只是一个想法;)
声音(100);
延迟(2);
nosound();
}
void main()
{
int x = 1,y = 2,ctr = 0;
_setcursortype(_NOCURSOR); //只是为了眼睛的舒适;)
clrscr();
gotoxy(1,1);
textcolor(白色);
cprintf(ESC退出,使用arrowkeys控制); //指令
窗口(1,2,80,25); //设置移动区域
put(x,y); //放笑脸
而(ctr!= 1)
开关(getch()){
//你可以在这里使用kbhit,但我只写了前文。
案例77 ://写
if(x> = 1&& x< 79){
gotoxy(x,y);
cprintf("");
x ++;
}
put(x,y);
snd();
break;
case 75:// left
if(x> 1&& x< = 80){
gotoxy(x,y);
cprintf("");
x - ;
}
put(x,y);
snd();
break;
case 72:// up
if(y <= 25&& y> 2) {
gotoxy(x,y);
cprintf("");
y--;
}
put(x,y);
snd();
休息; gotoxy(x,y);
cprintf("");
y ++;
}
put(x,y) ;
snd();
休息;
案例27://退出
ctr = 1;
休息;
}
textcolor( 7); //转回正常颜色
返回(0);
}
The c program is an example and should be correct.

I tried to compile the c file with MS studio 6.0. But failed with the
several err and warning messages. Does anyone know how to make it work?
Thanks.
Start by replaincing the illegal and illiterate return type for main.
The take out all the non-standard stuff (or ask about your program in a
Microsoft-specific newsgroup, mailing list, or tech support). That
means removing lines containing <conio.h>, <dos.h>, textcolor(),
gotoxy(), cprintf(), sound(), delay(), nosound(), _setcursortype(),
clrscr(), window(), and getch(). The remaining code is below. It now
has a broken switch statement.
You might also fix those magic numbers.

#include <stdio.h>
void put (int x,int y) { }

void snd (void){ }

int main(void)
{
int x=1,y=2,ctr=0;
put(x,y);
while(ctr!=1)
switch( /* need a variable here */){
case 77:
if(x>=1 && x<79) x++;
put(x,y);
snd();
break;
case 75:
if(x>1 && x<=80) x--;
break;
case 72:
if(y<=25 && y>2) y--;
break;
case 80:
if (y<24 && y>=2) y++;
break;
case 27:
ctr=1;
break;
}
return 0;
}

[OP''s code] /*file name way.c*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
void put (int x,int y) {
textcolor(CYAN);
gotoxy(x,y);
cprintf(".");
sound(440);
delay(3);
nosound();

}

void snd (void){ // it was just an idea ;)
sound(100);
delay(2);
nosound();
}

void main()
{
int x=1,y=2,ctr=0;
_setcursortype(_NOCURSOR); //just for eye comfort ;)
clrscr();
gotoxy(1,1);
textcolor(WHITE);
cprintf("ESC to exit, use arrowkeys to control"); //directive
window(1,2,80,25); // setting moving area
put(x,y); // puting smiling face
while(ctr!=1)
switch(getch()){
//you can use kbhit here but i wrote just ex.
case 77: // write
if(x>=1 && x<79){
gotoxy(x,y);
cprintf(" ");
x++;
}
put(x,y);
snd();
break;
case 75: // left
if(x>1 && x<=80){
gotoxy(x,y);
cprintf(" ");
x--;
}
put(x,y);
snd();
break;
case 72: // up
if(y<=25 && y>2){
gotoxy(x,y);
cprintf(" ");
y--;
}
put(x,y);
snd();
break;
case 80: // down
if (y<24 && y>=2){
gotoxy(x,y);
cprintf(" ");
y++;
}
put(x,y);
snd();
break;
case 27: // quit
ctr=1;
break;
}
textcolor(7); //turn back to normal color
return(0);
}



2004年7月14日星期三17:20: 11 -0500,kim< yj ****** @ hotmail.com>写道:
On Wed, 14 Jul 2004 17:20:11 -0500, kim <yj******@hotmail.com> wrote:
c程序是一个例子,应该是正确的。

我试图用MS studio 6.0编译c文件。但是失败了几个错误和警告信息。有谁知道如何使它工作?


如果程序是正确的,它将编译。您是否尝试过
解析消息。

谢谢。

这是c文件:
/ *文件名方式。 c * /
#include< stdio.h>
#include< conio.h>
#include< dos.h>
void put(int x,int y){
textcolor(CYAN);


textcolor声明在哪里? CYAN在哪里宣布?

gotoxy(x,y);


宣告gotoxy在哪里?

cprintf("。");
The c program is an example and should be correct.

I tried to compile the c file with MS studio 6.0. But failed with the
several err and warning messages. Does anyone know how to make it work?
If the program were correct, it would compile. Did you attempt to
resolve the messages.
Thanks.
Here is the c file:
/*file name way.c*/
#include <stdio.h>
#include <conio.h>
#include <dos.h>
void put (int x,int y) {
textcolor(CYAN);
Where is textcolor declared? Where is CYAN declared?
gotoxy(x,y);
Where is gotoxy declared?
cprintf(".");




同上多次


snip

<<删除电子邮件的del>>



Ditto many times

snip
<<Remove the del for email>>


这篇关于帮助:无法编译正确的c程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆