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

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -