I want to convert char pointer to unsigned char var
Are you sure? Converting a pointer from char to an unsigned char will not do any good - the value will be truncated to 1 byte, and in any case it will be meaningless. Perhaps you want to dereference the pointer and get the value indicated by it, then you should do something like this:
unsigned char part1 = (unsigned char)*pch2;
After your editing, I see that part1 is an array of characters - if your program crashes after using it, you are probably filling pch2 . Maybe you forgot the terminator '\0' ?
EDIT:
You see, now it is much better to answer your question, having all the necessary information. Do you need to use strtok ? Would that be good?
res result; char* ip = "123.23.56.33"; sscanf(ip, "%hhu.%hhu.%hhu.%hhu", &result.part1, &result.part2, &result.part3, &result.part4);
Maciek
source share