Solved

confused with " %c "

Posted on 2003-10-29
3
169 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 75 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

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 tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

724 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