R
rtillmore
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=
"2b0000203032577ef6a7325629024b0b0a0abc0b75392040bc3c1a2be4b7d93129f3f1de7b2a920000b73aedc3f247839cc3000000203032577ef6a7325629024b0b0a0abc0b75392040bc3c1a2be4b7d93129f3f1de7b2a920000b73aedc3f247839cc3";
char *toHex, *output[100];
unsigned long nVal;
int i,j;
for (i=0; i<100; i++){
strcpy(toHex,&temp[j]);
strcpy(toHex,&temp[j+1]);
nVal = strtoul(toHex, NULL, 16);
output = (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=
"2b0000203032577ef6a7325629024b0b0a0abc0b75392040bc3c1a2be4b7d93129f3f1de7b2a920000b73aedc3f247839cc3000000203032577ef6a7325629024b0b0a0abc0b75392040bc3c1a2be4b7d93129f3f1de7b2a920000b73aedc3f247839cc3";
char *toHex, *output[100];
unsigned long nVal;
int i,j;
for (i=0; i<100; i++){
strcpy(toHex,&temp[j]);
strcpy(toHex,&temp[j+1]);
nVal = strtoul(toHex, NULL, 16);
output = (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,