Turn int to char C -


i trying turn int 72, 101, 108 '72', '101', '108'.

the original program read string "hello\n" example, ascii values of each character, put int char array.

i tried:

int = 72; char b = (char)a;  

but convert int ascii character.

i tried:

int = 72; char b = + '0'; 

but not work @ all.

this have:

char buff[128]; strcpy(buff, "hello\n");  char tmp[128]; bzero(tmp, 128); // initialize array  int n = 0; while(buff[n] != '\n') {    int ascii = (int)buff[n];    en[n] = (char)ascii; // right here    n++; } strcat(tmp, "\n");  fprintf(stdout,"%s", tmp); 

since when did these '72', '101', '108' become chars? char values stored in 1 byte.

you can use sprintf or snprintf. convert integers char arrays.

int c = 4; char tin [some_length]; sprintf(tin , "%d", c); 

or

snprintf(tin , some_length, "%d", c); 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -