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=- 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/
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/
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.
Well darn, I've tried just about everything I can think of. I can't discern
what the problem is. What did I miss?
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 ---
wow. I feel very small now. Thanks for you help, hopefully I'll get better
at this soon enough! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
|
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.
|
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.
...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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:...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
| |