943,789 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 567
  • C RSS
Mar 23rd, 2009
0

Help needed !!!!!!!!!!!!!!!!

Expand Post »
I HAVE A VERY PECULIAR PROBLEM,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,


THE PROGRAMS I COMPILE SHUT DOWN AFTER COMPILING ONCE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

FOR EG-
I CREATED THIS PROGRAM FOR GETTING THE ASCII CODES OF AN ALPHABET ,,,,,,,,,,,,,,,,,,
AFTER I WROTE THE ALPHABET IN DOS IT DISPLAYED ITS VALUE AND SHUTDOWN,,,,,,,,,,,,,,,,
HOW CAN I ALTER MY PROGRAM TO TAKE IN AS MANY VALUES AS I WANT????????????????????????????????
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4.  
  5. main()
  6. {
  7. char a;
  8. clrscr();
  9. printf("enter any character\n");
  10. scanf("%c",&a);
  11. printf("the ascii code of %c is %d",a,a);
  12. getch();
  13. }
THANK YOU,,,,,,,,,,,,,,,,,,,,,
Last edited by Ancient Dragon; Mar 23rd, 2009 at 3:18 pm. Reason: add code tags
Similar Threads
Reputation Points: 6
Solved Threads: 0
Newbie Poster
PRATS 1990 is offline Offline
8 posts
since Mar 2009
Mar 23rd, 2009
0

Re: Help needed !!!!!!!!!!!!!!!!

Is your keyboard broken? It looks like sticky key with (!), (,) and (?).
Do you know that ALL caps represents YELLING! Not cool! Stop yelling at people you don't even know.

Learn how to use a loop, and include the scanf() inside one.
Last edited by Aia; Mar 23rd, 2009 at 12:04 pm.
Aia
Reputation Points: 2224
Solved Threads: 218
Nearly a Posting Maven
Aia is offline Offline
2,304 posts
since Dec 2006
Mar 23rd, 2009
0

Re: Help needed !!!!!!!!!!!!!!!!

DON'T SHOUT SO LOUD!
I have delicate ears you know...
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,738 posts
since Oct 2008
Mar 23rd, 2009
-1

Re: Help needed !!!!!!!!!!!!!!!!

Sorry guys didn't know that all caps means yelling as far as ,,,,,,,,,,,,,,,,!!!!!!!!!!!!!????????????????? go its just my style!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Reputation Points: 6
Solved Threads: 0
Newbie Poster
PRATS 1990 is offline Offline
8 posts
since Mar 2009
Mar 23rd, 2009
0

Re: Help needed !!!!!!!!!!!!!!!!

Click to Expand / Collapse  Quote originally posted by PRATS 1990 ...
I HAVE A VERY PECULIAR PROBLEM,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,


THE PROGRAMS I COMPILE SHUT DOWN AFTER COMPILING ONCE,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,

FOR EG-
I CREATED THIS PROGRAM FOR GETTING THE ASCII CODES OF AN ALPHABET ,,,,,,,,,,,,,,,,,,
AFTER I WROTE THE ALPHABET IN DOS IT DISPLAYED ITS VALUE AND SHUTDOWN,,,,,,,,,,,,,,,,
HOW CAN I ALTER MY PROGRAM TO TAKE IN AS MANY VALUES AS I WANT????????????????????????????????
  1. #include<stdio.h>
  2. #include<conio.h>
  3.  
  4.  
  5. main()
  6. {
  7. char a;
  8. clrscr();
  9. printf("enter any character\n");
  10. scanf("%c",&a);
  11. printf("the ascii code of %c is %d",a,a);
  12. getch();
  13. }
THANK YOU,,,,,,,,,,,,,,,,,,,,,
Well, that because you used the scanf function to read the value. The quick solution for this is to place two getch or getchar()! Or you will have to call the following function just above the getch() function or everything you read a char you will have to call this function before you read. That makes sure that the input buffer is clear and program won't shutdown!

  1. void clear_buffer( void )
  2. {
  3. int ch;
  4. while( ( ch = getchar() ) != '\n' && ch != EOF );
  5. }

-ssharish
Reputation Points: 73
Solved Threads: 20
Posting Whiz in Training
ssharish2005 is offline Offline
253 posts
since Dec 2006
Mar 24th, 2009
0

Re: Help needed !!!!!!!!!!!!!!!!

THANK U

ssharish2005
Reputation Points: 6
Solved Threads: 0
Newbie Poster
PRATS 1990 is offline Offline
8 posts
since Mar 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: persistence of a number
Next Thread in C Forum Timeline: Book on Windows Programming in C





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC