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

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.

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

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

commented: Well, your 'style' is irritating. -4

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

THANK U

ssharish2005

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.