i have the char value that contain the hexadecimal input.
char Val2[9];
strncpy (Val2, buffer+8, 8);
Val2[8]="\0";
printf("\nValue 2 : %s", Val2);
the Val2 value need to assign to :
int ptext[0].
how can i do that?
thanks
This is a discussion on String Conversion within the C Programming forums, part of the General Programming Boards category; i have the char value that contain the hexadecimal input. char Val2[9]; strncpy (Val2, buffer+8, 8); Val2[8]="
i have the char value that contain the hexadecimal input.
char Val2[9];
strncpy (Val2, buffer+8, 8);
Val2[8]="\0";
printf("\nValue 2 : %s", Val2);
the Val2 value need to assign to :
int ptext[0].
how can i do that?
thanks
Some questions?
- 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:
Code:#include <stdlib.h> #include <stdio.h> int main (int argc, char **argv) { char *str = "0x4a"; int n; sscanf (str, "%x", (unsigned int *) &n); printf ("n = %d\n", n); return 0; }
Last edited by edoceo; 03-17-2009 at 09:30 AM. Reason: typo