Hello,
I did a quick google search and nothing that was returned is quite
what I am looking for. I have a 200 character hexadecimal string that
I need to convert into a 100 character string.
This is what I have so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *temp=
"2b000020303257 7ef6a7325629024 b0b0a0abc0b7539 2040bc3c1a2be4b 7d93129f3f1de7b 2a920000b73aedc 3f247839cc30000 00203032577ef6a 7325629024b0b0a 0abc0b75392040b c3c1a2be4b7d931 29f3f1de7b2a920 000b73aedc3f247 839cc3";
char *toHex, *output[100];
unsigned long nVal;
int i,j;
for (i=0; i<100; i++){
strcpy(toHex,&t emp[j]);
strcpy(toHex,&t emp[j+1]);
nVal = strtoul(toHex, NULL, 16);
output[i] = (char*)nVal;
j=j+2;
}
printf("output = %d \n", output);
return 0;
}
This program is supposed to take the first two characters from temp
and convert the hex 2b to char which is +. Then it gets the next two
characters and repeats.
I compiled with gcc test.c -o test
When I run test I get:
segmentation fault
What did I do wrong?
Thanks,
I did a quick google search and nothing that was returned is quite
what I am looking for. I have a 200 character hexadecimal string that
I need to convert into a 100 character string.
This is what I have so far:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main ()
{
char *temp=
"2b000020303257 7ef6a7325629024 b0b0a0abc0b7539 2040bc3c1a2be4b 7d93129f3f1de7b 2a920000b73aedc 3f247839cc30000 00203032577ef6a 7325629024b0b0a 0abc0b75392040b c3c1a2be4b7d931 29f3f1de7b2a920 000b73aedc3f247 839cc3";
char *toHex, *output[100];
unsigned long nVal;
int i,j;
for (i=0; i<100; i++){
strcpy(toHex,&t emp[j]);
strcpy(toHex,&t emp[j+1]);
nVal = strtoul(toHex, NULL, 16);
output[i] = (char*)nVal;
j=j+2;
}
printf("output = %d \n", output);
return 0;
}
This program is supposed to take the first two characters from temp
and convert the hex 2b to char which is +. Then it gets the next two
characters and repeats.
I compiled with gcc test.c -o test
When I run test I get:
segmentation fault
What did I do wrong?
Thanks,
Comment