954,479 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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

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????????????????????????????????

#include<stdio.h>
#include<conio.h>


main()
{
char a;
clrscr();
printf("enter any character\n");
scanf("%c",&a);
printf("the ascii code of %c is %d",a,a);
getch();
}

THANK YOU,,,,,,,,,,,,,,,,,,,,,

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

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.

Aia
Nearly a Posting Maven
2,392 posts since Dec 2006
Reputation Points: 2,224
Solved Threads: 218
 

DON'T SHOUT SO LOUD!
I have delicate ears you know...

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

Sorry guys didn't know that all caps means yelling as far as ,,,,,,,,,,,,,,,,!!!!!!!!!!!!!????????????????? go its just my style!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

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????????????????????????????????

#include<stdio.h>
#include<conio.h>


main()
{
char a;
clrscr();
printf("enter any character\n");
scanf("%c",&a);
printf("the ascii code of %c is %d",a,a);
getch();
}

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!

void clear_buffer( void )
{
     int ch;
     while( ( ch = getchar() ) != '\n' && ch != EOF );
}


-ssharish

ssharish2005
Posting Whiz in Training
253 posts since Dec 2006
Reputation Points: 73
Solved Threads: 20
 

THANK U

ssharish2005

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

This question has already been solved

Post: Markdown Syntax: Formatting Help
You