473,748 Members | 7,590 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help: a correct c program can not be complied

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,2 5); // 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);
}

Nov 14 '05 #1
12 1608
kim <yj******@hotma il.com> writes:
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.

--
Keith Thompson (The_Other_Keit h) 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.
Nov 14 '05 #2
kim wrote:
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,2 5); // 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);
}

Nov 14 '05 #3
On Wed, 14 Jul 2004 17:20:11 -0500, kim <yj******@hotma il.com> wrote:
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>>
Nov 14 '05 #4
>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.
<conio.h> and <dos.h> are nonstandard include files.

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
Nov 14 '05 #5
On Wed, 14 Jul 2004 17:20:11 -0500, kim wrote:
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.

Nov 14 '05 #6
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

kim wrote:
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,2 5); // 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);
}


Nov 14 '05 #7
In <cd**********@2 16.39.134.18> Barry Schwarz <sc******@deloz .net> writes:
On Wed, 14 Jul 2004 17:20:11 -0500, kim <yj******@hotma il.com> wrote:
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.
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?


In <conio.h>, most likely, which is included.
cprintf(".");


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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #8
In <ln************ @nuthaus.mib.or g> Keith Thompson <ks***@mib.or g> writes:
<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
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #9
In 'comp.lang.c', go***********@b urditt.org (Gordon Burditt) wrote:
Quote those error messages. Do any of them have anything to do
with "Norton Antivirus"?


What ?

--
-ed- get my email here: http://marreduspam.com/ad672570
The C-language FAQ: http://www.eskimo.com/~scs/C-faq/top.html
C-reference: http://www.dinkumware.com/manuals/reader.aspx?lib=c99
FAQ de f.c.l.c : http://www.isty-info.uvsq.fr/~rumeau/fclc/
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1712
by: Chris | last post by:
Hi, I am trying to use the data access dll in one of my projects and was originally getting the error: 'Microsoft.Practices.EnterpriseLibrary.Data' does not have a strong name. I then followed instructions and gave the following assemblies strong name using mycompany.snk
66
5398
by: genestarwing | last post by:
QUESTION: Write a program that opens and read a text file and records how many times each word occurs in the file. Use a binary search tree modified to store both a word and the number of times it occurs. After the program has read the file, it should offer a menu with three choices. the first is to list all the words along with the number of occurences. The second is to let you enter a word, with the program reporting how many times the...
1
2181
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include <string>
2
2756
by: dasilva109 | last post by:
Hi guys I am new to C++ and need urgent help with this part of my code for a uni coursework I have to submit by Thursday //ClientData.h #ifndef CLIENTDATA_H #define CLIENTDATA_H #include <string>
2
1555
by: frame | last post by:
Hi, The other day, I was experimenting with Predicates and STL and came across a gotcha with the following program. The objective of the program is to remove those strings, from a vector of strings, whose size is of atleast a specified length (here 5) and contains atleast a specified number of punctuation characters, excluding '@' (here 2). There are 3 classes: Length and NumberOfSpecialChars in 'Parameters' namespace (which are just...
6
3358
by: AppleBag | last post by:
I'm having the worst time trying to login to myspace through code. Can someone tell me how to do this? Please try it yourself before replying, only because I have asked this a couple of times in the past in other places, and while the help was much appreciated, it seemed everyone just wanted to 'theoretically' explain how to do it, but when I tried to do it myself, I couldn't login. I want to simply pass the email address and password to...
3
1778
by: Dew | last post by:
Hello, iam new to programming, and ive been given a task in my Uni to complete certain exercises but i found it very difficulty to solve them. I was wandering if there is someone who can help me solve this problems. I cant tell u how much i will be gratefull if someone can help me. Please if anyone knows how to solve certain task reply to me.Thanks to all in advance. Tasks 1. Your are going to a restaurant where the tip is expected to be...
4
1742
by: sasimca007 | last post by:
Hello friends, I installed java with the following command: sudo apt-get update synaptic In synaptic i searched for sun-java6-jdk and marked and applied. After that i wrote a program and complied with javac /java/Hello.java it showed no errors and i run the program with java /java/Hello.java and it shows...
2
10040
by: hcaptech | last post by:
This is my Test.can you help me ? 1.Which of the following statement about C# varialble is incorrect ? A.A variable is a computer memory location identified by a unique name B.A variable's name is used to access and read the value stored in it C.A variable is allocated or deallocated in memory during runtime D.A variable can be initialized at the time of its creation or later 2. The.……types feature facilitates the definition of classes...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9374
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9325
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4876
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2787
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.