Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

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..
0
Swaminathan_K
Asked:
Swaminathan_K
  • 2
  • 2
  • 2
  • +2
5 Solutions
 
ZoppoCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
slightwv (䄆 Netminder) 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)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
 
jaiminpsoniCommented:
Use it like this....

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

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now