I'm getting a segmentation fault when assigning the value stored at a pointer to a local variable in a function. I have a hunch that I'm handling pointers poorly, but I can't seem to figure out what the issue is. Any ideas? Thanks!
I've tried adding breakpoints, and I've determine that the actual seg fault happens at "int i = *AlignCounter;"
When looking at the variables window, I see this:
Here's the function where the seg fault happens:
void align_S_T(int *StringCounterS, int
*StringCounterT, int *AlignCounter, char *StringS, char
*StringT, char *AlignmentS, char *AlignmentT)
{
//Local Variables
int i = *AlignCounter; //<--Seg Fault Line
int s = *StringCounterS;
int t = *StringCounterT;
//Set Strings
AlignmentS[i] = StringS[s];
AlignmentT[i] = StringT[t];
//Increment Counters
*AlignCounter++;
*StringCounterS++;
*StringCounterT++;
}
Here's how the pointers are created and allocated in main:
int* StringCounterT; //T String Counter
int* AlignCounter; //Align Counter
StringCounterS=0;
StringCounterT=0;
AlignCounter=0;
0x0
(at the very base of the System Reserved memory range)? What do you think is stored there?int i = *AlignCounter; //<--Seg Fault Line
is a good indication of the answer to the first question. In other wordsAlignCounter=0;
stores the Address0
as the value forAlignCounter
and when you attempt to access the memory location you have no right to access, BAM SegFault. - David C. Rankinalign_S_T
function did you allocated dynamic memory toAlignCounter
? - Miguel Ángel Retamozo Sanchez