View Single Post
  #5 (permalink)  
Old 04-15-2007, 09:49 AM
siren siren is offline
Newbie
 
Join Date: Apr 2007
Posts: 10
Credits: 0
Rep Power: 0
siren is on a distinguished road
Default

thanks again for all the help void!! I tried out your code and it worked out very well...except there seems to be some problems... First of all, I really couldn't use codes such as fflush and so on. I've only learned the real basics such as looping via if, and so on so I really wasn't allowed to use all those advanced codes...sry I didn't mention that before hand...So I used void's program as a reference and fixed up my program, but it just isn't working... this is what I did...

#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);


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);
}


}}

The result of this code was 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: 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
>> 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

command 1, 3, and q work perfectly....however 2: CHAR -> ASCII code just isn't working... it won't let me enter the character to convert...I can't figure it out....another problem was that it shows the menu twice after each attempt...please help!
Reply With Quote

Sponsored Links