Folks,
Programming has been a life-long hobby. It was never my means to make a living - though I have written quite a lot of C (well, not much compared with some, but one program had about 8,000 lines of C, encompassing most C constructs). However, I moved to AutoHotKey about 10 years ago, and have just come back to C in the last few weeks - and I seem to have forgotten an alarming amount.
The below, however, is so simple that I can hardly believe I have forgotten that much. Also, it is a simplification of something I copied/pasted from a C forum. Their program gave me a segmentation fault, and I simplified it down to what you see below - but I still get the fault. Is this me, or is there something I'm not understanding about the C::B implementation?
#include <stdio.h>
#include <stdlib.h>
void main()
{
char *s = "ABCDEF"; // this line works. GDB shows s ...... 0x403024 _Jv_RegisterClasses+4206628>"ABCDEF"
temp = s[3]; // temp is assigned a value of 'D', which is what I expected
s[3] = 'h'; // this line gives a segmentation fault.
}
I tried replacing the offending line with ...
... but I still get the segmentation fault - yet if figure that the address of s[3] must be correctly resolved, because "temp = s[3];" works as expected.
I know this is a C::B forum, not a C forum, but would somebody please dig me out? I'm all at sea, trying to see what's wrong with my C.