Solved

Different character when the size increases from 255

Posted on 2011-03-04
10
334 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 30

Accepted Solution

by:
Zoppo earned 50 total points
Comment Utility
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 76

Expert Comment

by:slightwv (䄆 Netminder)
Comment Utility
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
Comment Utility
void main ()
{
char name :='7892';
printf("%c \n",name);
}
0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 50 total points
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 8

Assisted Solution

by:Subrat (C++ windows/Linux)
Subrat (C++ windows/Linux) earned 50 total points
Comment Utility
//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
Comment Utility
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
Comment Utility
Actually... it should be like....

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

Author Closing Comment

by:Swaminathan_K
Comment Utility
Thanks . I got the answer.
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

772 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now