Computing.Net > Forums > Programming > cprintf

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

cprintf

Reply to Message Icon

Name: jacky
Date: August 11, 2002 at 11:16:03 Pacific
Comment:

#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



Sponsored Link
Ads by Google

Response Number 1
Name: cup
Date: August 11, 2002 at 11:40:06 Pacific
Reply:

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.


0

Response Number 2
Name: jacky
Date: August 11, 2002 at 13:19:52 Pacific
Reply:

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


0

Response Number 3
Name: Victor516
Date: August 11, 2002 at 16:29:20 Pacific
Reply:

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


0

Response Number 4
Name: jacky
Date: August 11, 2002 at 17:21:10 Pacific
Reply:

thank you
if I remove them. The message shows that they are undefined function.


0

Response Number 5
Name: NULL
Date: August 11, 2002 at 20:58:21 Pacific
Reply:

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


0

Related Posts

See More



Response Number 6
Name: NULL
Date: August 11, 2002 at 21:03:20 Pacific
Reply:

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



0

Response Number 7
Name: NULL
Date: August 11, 2002 at 21:07:47 Pacific
Reply:

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:))


0

Response Number 8
Name: jacky
Date: August 11, 2002 at 21:50:24 Pacific
Reply:

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()


0

Response Number 9
Name: NULL
Date: August 11, 2002 at 22:40:01 Pacific
Reply:


Hi Jacky

The 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*/
#include

int 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
#include

int 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!


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: cprintf

cprintf, gotoxy in Microsoft Visual C www.computing.net/answers/programming/cprintf-gotoxy-in-microsoft-visual-c/1716.html

How to change font and background c www.computing.net/answers/programming/how-to-change-font-and-background-c/10470.html

C++ Dos.. Color!? www.computing.net/answers/programming/c-dos-color/2848.html