Solved

Different character when the size increases from 255

Posted on 2011-03-04
10
340 Views
Last Modified: 2012-05-11
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
Comment
Question by:Swaminathan_K
  • 2
  • 2
  • 2
  • +2
10 Comments
 
LVL 31

Accepted Solution

by:
Zoppo earned 50 total points
ID: 35037597
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
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 35037603
What are you assigning to the variable and what is being printed?

Post the code in question and what the output is.
0
 

Author Comment

by:Swaminathan_K
ID: 35038109
void main ()
{
char name :='7892';
printf("%c \n",name);
}
0
ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

 
LVL 77

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 50 total points
ID: 35038271
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
 
LVL 9

Assisted Solution

by:Subrat (C++ windows/Linux)
Subrat (C++ windows/Linux) earned 50 total points
ID: 35039415
//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
 
LVL 5

Assisted Solution

by:jaiminpsoni
jaiminpsoni earned 100 total points
ID: 35043721
Use it like this....

void main ()
{
char * name :='7892';
printf("%s \n",name);
}
0
 
LVL 5

Assisted Solution

by:jaiminpsoni
jaiminpsoni earned 100 total points
ID: 35043722
Actually... it should be like....

void main ()
{
char * name = "7892";
printf("%s \n",name);
}
0
 

Author Closing Comment

by:Swaminathan_K
ID: 35063386
Thanks . I got the answer.
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Adjust Mfcapp 29 172
C simple state machine for client server handshake 4 337
Line meaning 9 87
How to increment counter variables in ANSI  C (Not C# or C++). 9 18
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question