Hi,
I've produced some code (some of which is below) that contains a segmentation error on line 87 ("ascii[d] = '\0';" in my htoi function). I'm creating a function to convert a hexdecimal string into a standard ascii string. I'm not sure that the problem is really based on line 87 but is certainly caused by my integration of my 'd' variable into my main 'for' loop. Anyway I've placed a breakpoint on line 86 ('break 86') in an effort to see what my variables look like before the segmentation error. However using 'print x', where x is any of the variables defined in this function, gdb returns meaninglessly big values for x. What am I doing wrong?
Another issue I worry about is how does gdb know which variable to examine when the automatic variable 'a', say, is contained in different functions in the same file.
Code:
void htoi(char hex[], char ascii[])
{
int part1, part2, a, b, c, d;
for ((a = 0) && (d = 0); hex[a] != 0; ++a && ++d) {
part1 = hex[a];
++a;
part2 = hex[a];
part1 = ((part1 - 48) * 16);
for ((b = 97) && (c = 10); b < 103; ++b && ++c) {
if (part2 == b) {part2 = c;}}
for ((b = 48) && (c = 0); b < 58; ++b && ++c) {
if (part2 == b) {part2 = c;}}
ascii[d] = (part1 + part2);
printf("\nP1 = %d\nP2 = %d\nAscii[d] = %d", part1, part2, ascii[d]);}
++d;
ascii[d] = '\0';
for (b = 0; ascii[b] != 0; ++b) {
printf("\nAscii Array(%d) contains: %d", b, ascii[b]);}
}