Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
#include
int main(void)
{
int i,j;
void textbackground(int);
void textcolor(int);
int cprintf();
clrscr();
for (i=0; i<9; i++)
{
for (j=0; j<80; j++)
cprintf("c");
textcolor(i+1);
textbackground(i);
}
return 0;
}i don't know why it can't be run
the problem is focus on the syntax cprintf
Thank you for replying

I don't know very much about cprintf. It may be the same as _cprintf on VC++. I've never used it before. Anyway, from the info, it looks the same as printf.
1) What include file are you including? It didn't come out in the posting. On VC++, it needs conio.h.
2) Does changing it to _cprintf help?
3) If all else fails, change the include to stdio.h and the cprintf to printf.

#include
#include
int main(void)
{
int i,j;
void textbackground(int);
void textcolor(int);
void cprintf();for (i=0; i<9; i++)
{
for (j=0; j<80; j++)
cprintf("c");
textcolor(i+1);
textbackground(i);
}
return 0;
}
thank you for replaying, the message said:Extra parameter in call to cprintf() in function main()
i don't know how to define the function cprintf()
at the top.

void textbackground(int);
void textcolor(int);
void cprintf();
remove this from main that is not needed there they are prototyped in the header files

May be this code will help:
*********************************************************************
/*Include stdio.h for cprintf()*/
#include
/*You must include conio.h for clrscr(),
textbackground() and textcolor()*/
#include/*Once you have included these files there
is no need to prototype them*/int main(void)
{
int i, j;clrscr();
/*
cprintf(); is used to display coloured strings to the
console if you use printf() characters will be displayed
without colour.
*/
for(i=0; i/*An user defined function*/
void my_function()
{
printf("My name is NULL\n");
}void main()
{
/*Calls the above function*/
my_function();
}
*********************************************************************2)second type function is defined below main
*********************************************************************
#include/*In this case a function prototype should be specified*/
void my_function();
/*Not inside the main function but outside and above it*/void main()
{
/*Calls the above function*/
my_function();
}/*An user defined function*/
void my_function()
{
printf("My name is NULL\n");
}*********************************************************************
For the functions which are predefined example cprintf(), getenv(),
remove() etc including the corresponding header file will be
sufficient

sorry that didn't show up properly:
*********************************************************************
/*Include stdio.h for cprintf()*/
#include
/*You must include conio.h for clrscr(),
textbackground() and textcolor()*/
#include/*Once you have included these files there
is no need to prototype them*/int main(void)
{
int i, j;clrscr();
/*
cprintf(); is used to display coloured strings to the
console if you use printf() characters will be displayed
without colour.
*/for(i=0; i
/*An user defined function*/
void my_function()
{
printf("My name is NULL\n");
}void main()
{
/*Calls the above function*/
my_function();
}
*********************************************************************2)second type function is defined below main
*********************************************************************
#include/*In this case a function prototype should be specified*/
void my_function();
/*Not inside the main function but outside and above it*/void main()
{
/*Calls the above function*/
my_function();
}/*An user defined function*/
void my_function()
{
printf("My name is NULL\n");
}*********************************************************************
For the functions which are predefined example cprintf(), getenv(),
remove() etc including the corresponding header file will be
sufficient

Now why doesn't that show up properly :)
If you want to see that then please say so
i will post it another time(this time neatly:))

NULL:thank you very much for your replying
i am so glad to get your neatly post.
Could you post easier one which doesn't need other functions out of main()
:)
i hope it can be finished just in the main()

Hi JackyThe first thing you have to note is that
even the simplest working program will need some
functions outside main(), you can use predefined
functions like cprintf() clrscr() etc, so that
there is no use to prototype them in your source
file, including the respective header files will be
sufficient.first of all as you said an easier program:
*******************************************************
/*a simple program*/
#includeint main(void)
{
/*
this is a simple program even then we need a function
outside of the main function, namely printf(); it is
defined in stdio.h.
*/
printf("My name is NULL\n");
return 0;
}
*******************************************************the modified version of your program:
*******************************************************
#include
#include
int main(void)
{
int i,j;
/*
these functions are already prototyped in
conio.h and stdio.h
so we dont need them here :), instead
we can use them directly
like clrscr(); etc
void textbackground(int);
void textcolor(int);
int cprintf();
*/
clrscr();
for (i=0; i
#includeint main(void)
{
int i, j;
char name[19] = "My name is NULL :)";for(i=0;i<19;i++){
/*delay is a function defined in dos.h*/
delay(100); /*causes a delay of 100 milliseconds*/
/*putchar is a function defined in stdio.h*/
putchar(name[i]);/*puts a character to the screen*/
}
return 0;
}*******************************************************
These programs have all been compiled without errors using
Turbo C++ Version 3.00, if you find any errors during
compilation please tell me :)We can finish a program with in the main itself without
including header files, but we will have to use assembly:(I hope this helped you!

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |