hi guys... I seriously need help...
I've been working on this program for the past few days, and well....it just isn't working out at all...It's starting to get really annoying..
I have to create a program that
1) changes an ASCII code entered by the user into the appropriate letter.
2)changes a character entered in by the user into ASCII code
3) Display an ASCII TABLE
4) and when the letter "q" is entered, the program ends...
and all I could come up with is this
CODE
#include <stdio.h>
int main()
{
int i, type;
char c;
type = 0;
printf("ASCII character program\n\n");
while(type != 'q')
{
printf(" Input 1, 2, 3, or q\n");
printf(" 1: ASCII code -> CHAR\n");
printf(" 2: CHAR -> ASCII code\n");
printf(" 3: DISPLAY ASCII TABLE\n");
printf(" q: End of this Program\n");
printf(">>");
scanf("%c", &type);
fflush(stdin);
if(type == '1')
{
printf("ASCII code -> CHAR\n");
printf(" Input ASCII code: ");
scanf("%d", &c);
printf(" Character for ASCII code %d is -> '%c'\n\n", c, c);
}
else if(type == '2')
{
printf("CHAR -> ASCII code\n");
printf(" Input a character: ");
scanf("%c", &c);
printf(" ASCII code for character '%c' is -> '%d'\n\n", c, c);
}
else if(type == '3')
{
printf("ASCII code table for 1-127\n");
for(i = 1; i <= 127; i++)
printf("Character for ASCII code %d is -> '%c'\n", i, i);
}
}
return 0;
}
AND I want the program to run like so...
ASCII character program
Input 1,2,3, or q
1: ASCII code -> CHAR
2: CHAR -> ASCII code
3: Display ASCII TABLE
q: End of this program
1
input ASCII code
123
Character for ASCII code 123 is -> '{'
Input 1,2,3, or q
1: ASCII code -> CHAR
2: CHAR -> ASCII code
3: Display ASCII TABLE
q: End of this program
2
input a character
r
ASCII code for character 'r' is -> 114
Input 1,2,3, or q
1: ASCII code -> CHAR
2: CHAR -> ASCII code
3: Display ASCII TABLE
q: End of this program
q
END
However it runs like so...
$ ./a.exe
ASCII character program
Input 1, 2, 3, or q
1: ASCII code -> CHAR
2: CHAR -> ASCII code
3: DISPLAY ASCII TABLE
q: End of this Program
>>1
ASCII code -> CHAR
Input ASCII code: 96
Character for ASCII code 96 is -> '`'
Input 1, 2, 3, or q
1: ASCII code -> CHAR
2: CHAR -> ASCII code
3: DISPLAY ASCII TABLE
q: End of this Program
>> Input 1, 2, 3, or q
1: ASCII code -> CHAR
2: CHAR -> ASCII code
3: DISPLAY ASCII TABLE
q: End of this Program
>>2
CHAR -> ASCII code
Input a character: ASCII code for character '
' is -> '10'
Input 1, 2, 3, or q
1: ASCII code -> CHAR
2: CHAR -> ASCII code
3: DISPLAY ASCII TABLE
q: End of this Program
>>q
What it is doing wrong is when the user enters 2, to change the CHAR to ASCII code, it won't allow the user to enter anything... The program also displays the main menu twice after each attempt...I can't figure it out....I been working like mad on it for a few days, but it isn't working at all..HELPPP!!!!