473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Just need a few questions answered...

Code:

#include <stdio.h>
int main(void)
{
int in;

printf("Please enter an ascii number to convert:\n");
scanf("%d \n", &in);
printf("You entered %d, the regular value is %c", in, in);
getchar();
getchar();
getchar();
getchar();
return 0;
}

This program is supposed to convert an ascii number value to its regular
equivalent. Example: entering 90 will give you a Z. Why then do I need to
type in 90 twice? Also, why do I need to have so many "getchar()"'s at the
end of the code to prevent the window from closing right away?

Thanks!
-=Allen=-

Nov 14 '05 #1
6 1317


SithVegeta wrote:
Code:

#include <stdio.h>
int main(void)
{
int in;

printf("Please enter an ascii number to convert:\n");
scanf("%d \n", &in);
printf("You entered %d, the regular value is %c", in, in);
getchar();
getchar();
getchar();
getchar();
return 0;
}

This program is supposed to convert an ascii number value to its regular
equivalent. Example: entering 90 will give you a Z. Why then do I need to
type in 90 twice? Also, why do I need to have so many "getchar()"'s at the
end of the code to prevent the window from closing right away?

Thanks!


It may be as simple as forcing a flush of the output buffer. Try either
changing the last printf statement (at the newline char to the end) to:

printf("You entered %d, the regular value is %c\n", in, in);

or you can leave the last printf statement unchanged but add
fflush(stdout);
just after it.

--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapidsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #2


Al Bowers wrote:


SithVegeta wrote:
Code:

#include <stdio.h>
int main(void)
{
int in;
printf("Please enter an ascii number to convert:\n");
scanf("%d \n", &in);
printf("You entered %d, the regular value is %c", in, in);
getchar();
getchar();
getchar();
getchar();
return 0;
}

This program is supposed to convert an ascii number value to its regular
equivalent. Example: entering 90 will give you a Z. Why then do I need to
type in 90 twice? Also, why do I need to have so many "getchar()"'s at
the
end of the code to prevent the window from closing right away?

Thanks!

It may be as simple as forcing a flush of the output buffer. Try either
changing the last printf statement (at the newline char to the end) to:

printf("You entered %d, the regular value is %c\n", in, in);

or you can leave the last printf statement unchanged but add
fflush(stdout);
just after it.


Also, take the whitespace out of the scanf format string.
scanf("%d",&in);

--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapidsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #3
Ah Crud

I tried both but I seems I still need to enter the value twice and it
still requires four getchar()'s to be there. Sorry for the trouble I just
started learning C and I've been reading "C Primer Plus (4th)" but I can't
seem to get past this review exercise in chapter three. I'll try entering
this into another compiler to see if I still get this problem.

Nov 14 '05 #4
Well darn, I've tried just about everything I can think of. I can't discern
what the problem is. What did I miss?

Nov 14 '05 #5
SithVegeta wrote:
Ah Crud

I tried both but I seems I still need to enter the value twice and it
still requires four getchar()'s to be there. Sorry for the trouble I just
started learning C and I've been reading "C Primer Plus (4th)" but I can't
seem to get past this review exercise in chapter three. I'll try entering
this into another compiler to see if I still get this problem.


#include <stdio.h>
int main(void)
{
int in;
printf("Please enter an ascii number to convert:\n");
scanf("%d", &in);
printf("You entered %d, the regular value is %c\n", in, in);
return 0;
}

I took out whitespace from the scanf string and removed the
getchar() statements and added '\n' to the printf().
--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #6
wow. I feel very small now. Thanks for you help, hopefully I'll get better
at this soon enough!

Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Conax | last post by:
Hi there, My boss is hoping that I can come up with a page that displays some information. The information will always be displayed on specific part of the page, with auto refresh. But he...
13
by: Lumpierbritches | last post by:
I'm curious as to why some questions posted here get results and solutions, while others are answered in a seemingly foreign language and I can't begin to comprehend or understand the answers that...
5
by: Jim Holder | last post by:
I tried building libpcap and tcpdump from my Red Hat 7 RPMs. The tcpdump make couldn't find ioccom.h and sockio.h. When a header file is missing, how do you find it? Thanks.
3
by: E.F. | last post by:
I have a Matrox RT.X100 graphic card connected to a digital camera. Now i need to develop a Vision Robotic System in C++ and i need to use some DLL to caprture frames from the graphic card. ...
23
by: Adam | last post by:
I am coding a microkernel based off of Tanebaum's theroy. For Isis to be extensible, fast, and secure, it has been decided it will be a microkernel. Not in the old Mach sense of the word, but in...
2
by: nicks | last post by:
Hi there ! i need a bit of help as i am a new c++ user to write a program. The program should ask the user n questions or until the user enters -1 to Exit (n should be a constant and it should be...
1
by: TexCube | last post by:
Hello everyone, I have an urgent question. Can data be pulled from an access database table to create a directory that can be printed out and bound together? I need to have each row of a...
16
by: marc_r_bertrand | last post by:
To all asp/db pros: The quiz code below works. But there is a problem when too many questions are answered (radio buttons clicked). I am not an asp pro. So, is there a pro out there or an...
5
by: pefok | last post by:
Hello everyone, One of my course works is to implement a java based quiz system. the program consists of two modules one for the teacher to create, set questions , answers and the number of...
0
by: yragcom1 | last post by:
If someone could tell me how I could use .htaccess to make the URLs in this site pretty, I would be forever grateful. www.answered-questions.com Instead of having this URL:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.