[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

confused with " %c "

Posted on 2003-10-29
3
Medium Priority
?
171 Views
Last Modified: 2010-04-15

{
 int ch;

 ch = getchar();
 printf("%d", ch);
}

lets say i enter .. 1
output will be   .. 49   the ASII value of the character 1  


the above i have no problems with,
BUT,,  can someone explain the following..


{
 int ch;

 cscanf("%c", &ch);
 printf("%d", ch);
}

lets say i enter .. 1
output will be   .. 4210737  where does this value come from??

A clear and easy explanation would be greatly appreciated.
thanks..

mike...

using devc++
0
Comment
Question by:mikem_2au
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 10

Expert Comment

by:Sys_Prog
ID: 9641822
Initialse the int variable to something [say ch = 0 ] and your problem would be solved

0
 
LVL 10

Accepted Solution

by:
Sys_Prog earned 300 total points
ID: 9641842
Basically when u are using %c, only one byte of the integer variable is getting populated with the data and the other byte contains it's initial junk value

Thus the result u obtained

After initialising it to 0, everything works fine
0
 

Author Comment

by:mikem_2au
ID: 9641965
confusion gone..

thank's for the explanation, and the quick response.

mike..
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!

Question has a verified solution.

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

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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.

656 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