Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,844 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,354 people online right now. Registration is fast and FREE... Join Now!




how to print a character

 
Reply to this topicStart new topic

how to print a character

umer_alvi
22 Feb, 2007 - 03:59 PM
Post #1

New D.I.C Head
*

Joined: 21 Feb, 2007
Posts: 7


My Contributions
void main(void)
{
char a;
printf("%c",a);
}
i want to print for example "a" in C language.
But receiving error
i dont want to print any value of a. Just the character.
User is offlineProfile CardPM
+Quote Post

Manny
RE: How To Print A Character
22 Feb, 2007 - 04:17 PM
Post #2

New D.I.C Head
*

Joined: 30 May, 2006
Posts: 44


My Contributions
QUOTE(umer_alvi @ 22 Feb, 2007 - 04:59 PM) *

void main(void)
{
char a;
printf("%c",a);
}
i want to print for example "a" in C language.
But receiving error
i dont want to print any value of a. Just the character.


in c++

CODE


int main()
{

       char a;

       cout << a;

       return 0;
}


User is offlineProfile CardPM
+Quote Post

PennyBoki
RE: How To Print A Character
22 Feb, 2007 - 04:24 PM
Post #3

system("revolution");
Group Icon

Joined: 11 Dec, 2006
Posts: 2,011



Thanked: 7 times
Dream Kudos: 500
Expert In: Java,C++,C

My Contributions
QUOTE(umer_alvi @ 22 Feb, 2007 - 04:59 PM) *

void main(void)
{
char a;
printf("%c",a);
}
i want to print for example "a" in C language.
But receiving error
i dont want to print any value of a. Just the character.


What do you mean you dont wanna print the value just the character???
If you wanna print a you have to assign it as a value for the
variable a.

char a='a';
User is offlineProfile CardPM
+Quote Post

bestbat
RE: How To Print A Character
22 Feb, 2007 - 06:17 PM
Post #4

New D.I.C Head
*

Joined: 14 Feb, 2007
Posts: 32


My Contributions
Like PennyBoki said, you need to assign a value to your variable a:

The full program would be:

CODE

#include <stdio.h> /* Needed for the print function */

void main(void)
{
char a='b'; /* Sets the variable a to equal character b Note: I am using b to highlight how this will work */
printf("%c", a); /* This should print the character b */
printf("\n"); /* Prints a blank line, this is not needed but will make this program easier to read once compiled */
}


This post has been edited by bestbat: 22 Feb, 2007 - 06:19 PM
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 10:11AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month