- What will Val2 contain after your call to strncpy(..)?
- Will this always be a valid hexadecimal number represented as a string? (i.e. "0x0A", "0xDEADBEEF", etc)
Without knowing exactly what you have in mind, I think that the function int sscanf(const char *str, const char *format, ...); might solve your issues.
a simple example:
main (int argc, char **argv)
char *str = "0x4a";
sscanf (str, "%x", (unsigned int *) &n);
printf ("n = %d\n", n);