Help: a correct c program can not be complied

K

kim

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);
}
 
K

Keith Thompson

kim said:
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);
}

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.
 
M

Martin Ambuhl

kim said:
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]
 
B

Barry Schwarz

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(".");

Ditto many times

snip


<<Remove the del for email>>
 
G

Gordon Burditt

The c program is an example and should be correct.

All of the functions you call here are non-standard functions,
except for the ones you define. main returns int, not void.
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?

Quote those error messages. Do any of them have anything to do
with "Norton Antivirus"?

Gordon L. Burditt
 
?

=?iso-8859-1?q?Nils_O=2E_Sel=E5sdal?=

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.
I'm very sure those error messages will actually be very helpful.
Read them, fix them.
 
S

Saroj Pattnaik

Functions you used are not availabele in MS studio header files.
conio.h and dos.h
You can use TC compilers to work it okay.
saroj
 
D

Dan Pop

In said:
<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.

Well, they aren't Windows headers, either, so there is no point in
redirecting to a Windows-specific newsgroup. Especially as long as
a newsgroup dedicated to MSDOS programming still exists.

Dan
 
D

Dan Pop

In said:
If the program were correct, it would compile. Did you attempt to
resolve the messages.


Where is textcolor declared? Where is CYAN declared?


Where is gotoxy declared?


Ditto many times

Ditto.

If you want to complain about non-standard functions, then do so, rather
than asking irrelevant (to the OP) questions.

Dan
 
K

Keith Thompson

Well, they aren't Windows headers, either, so there is no point in
redirecting to a Windows-specific newsgroup. Especially as long as
a newsgroup dedicated to MSDOS programming still exists.

Good point (it's comp.os.msdos.programmer).
 
B

Barry Schwarz

In <conio.h>, most likely, which is included.

Since I compiled the OP's code exactly as written using the same
compiler he specified and since I received 21 diagnostics about
undefined functions and undefined identifiers, including the few I
mentioned, I am pretty certain that your assumption is incorrect.
Ditto.

If you want to complain about non-standard functions, then do so, rather
than asking irrelevant (to the OP) questions.

It must be wonderful to know what was relevant to the OP without even
checking the few facts available.

I'm sorry my pedagogical technique of requiring analysis rather than
spoon feeding the answer doesn't meet with your approval.


<<Remove the del for email>>
 
D

Dan Pop

In said:
Since I compiled the OP's code exactly as written using the same
compiler he specified and since I received 21 diagnostics about
undefined functions and undefined identifiers, including the few I
mentioned, I am pretty certain that your assumption is incorrect.

Nope, it ain't. You're simply not using the implementation for which
the code was written (most likely, some TURBO C compiler). Apparently,
neither did the OP.

Dan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top