• C

Different character when the size increases from 255

Hi All,

Iam new to C programming . Can anyone tell me when I assign a character more then 255 characters to char variable in C, Iam getting a different charctaer when I print it.

Thanks in advance..
Swaminathan_KAsked:
Who is Participating?
 
ZoppoConnect With a Mentor Commented:
Hi Swaminathan_K,

could you post some code what you're trying?

Maybe you're mixing up 'char' and 'char*' - a 'char' is a variable to hold one single character, a 'char*' is a pointer to the first character of a string which can be of any length but has to be allocated before and released after used.

ZOPPO
0
 
slightwv (䄆 Netminder) Commented:
What are you assigning to the variable and what is being printed?

Post the code in question and what the output is.
0
 
Swaminathan_KAuthor Commented:
void main ()
{
char name :='7892';
printf("%c \n",name);
}
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
slightwv (䄆 Netminder)Connect With a Mentor Commented:
char by itself is a single character.

printf with a %c prints a single character.

You need an 'array' of characters and a %s in printf.

http://www.learn-programming.za.net/programming_c_learn07.html
0
 
Subrat (C++ windows/Linux)Connect With a Mentor Software EngineerCommented:
//char name :='7892';
char const------------->single char within single quote. Here hope you need a string(array of chars)

std::string  str ="7892"

or

char* str = "7892";
0
 
jaiminpsoniConnect With a Mentor Commented:
Use it like this....

void main ()
{
char * name :='7892';
printf("%s \n",name);
}
0
 
jaiminpsoniConnect With a Mentor Commented:
Actually... it should be like....

void main ()
{
char * name = "7892";
printf("%s \n",name);
}
0
 
Swaminathan_KAuthor Commented:
Thanks . I got the answer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.