C programming Hex to Char -
what i'm trying have user input hex number number converted char , displayed monitor continue until eof encountered.i have opposite of code done converts char hex number. problem i'm running how hex number user used getchar() char2hex program. there similar function hex numbers?
this code char2hex program
#include <stdio.h> int main(void) { char mychar; int counter = 0; while (eof != (mychar = getchar())) { /* don't convert newline hex */ if (mychar == '\n') continue; printf("%02x ", mychar); if (counter > 18) { printf("\n"); counter = -1; } counter++; } system("pause"); return 0; } this want program except continuously
#include <stdio.h> int main() { char mychar; printf("enter hex number: "); scanf("%x", &mychar); printf("equivalent char is: %c\n", mychar); system("pause"); return 0; } any appreciated thank
because chars , ints can used interchangably in c, can use following code:
int main(void) { int mychar; printf("enter hex number: "); scanf("%x", &mychar); printf("equivalent char is: %c\n", mychar); system("pause"); return 0; } if want loop enclose in while loop in example code.
edit: can try out working code here http://ideone.com/yyvz85
Comments
Post a Comment