fgetc() and TABS, Extended ASCII
Hi all,
I am reading characters from a file input stream and printing out their 1. ASCII value or control mnemonic 2. Binary Value 3. Hexidecimal Value.
My problem is if the the current character I am reading in and then outputing is a TAB it prints an actual tab to screen. I would like instead to be able to print "TAB" for example.
FILE *fp;
inchar = fgetc(fp)
printf("%x",inchar);
etc.
Any help would be appreciated.
Re: fgetc() and TABS, Extended ASCII
Quote:
Originally posted by eddiemjm
Hi all,
I am reading characters from a file input stream and printing out their 1. ASCII value or control mnemonic 2. Binary Value 3. Hexidecimal Value.
My problem is if the the current character I am reading in and then outputing is a TAB it prints an actual tab to screen. I would like instead to be able to print "TAB" for example.
FILE *fp;
inchar = fgetc(fp)
printf("%x",inchar);
etc.
Any help would be appreciated.
By control mnemonic do you mean STX, TAB, ESC, etc? You need to create a string array for all the characters below 0x20
Code:
char *CtrlArray[] = {"NUL", ... ,"BKSP", "TAB", ... };
and during your loop, do something similar to what Thantos suggested:
Code:
if (inchar < ' ')
printf("%s", CtrlArray[inchar]);
else
printf("%x", inchar);