Note: C is Microsoft C Compiler.
I'm having trouble with the following code.
*Roomsize = (int*)calloc(sizeof(int),sched->numberOfRooms);
roomIndex = 0;
for(roomIndex=0; roomIndex< sched->numberOfRooms; roomIndex++)
{
fscanf(inputFile,"%d",&lineInput);
numberOfLinesRead++;
*Roomsize[roomIndex] = lineInput;
}
This is in a separate C file. I wasn't having this problem until I decided to separate things out to make them more maintainable and I think I'm just getting a little mixed up with pointers.
The calloc works fine.
On the first iteration of the loop, element zero of roomIndex gets set properly.
However the second element (element 1) in the loop, always results in an access violation at runtime.
I run into this problem later in my code too with a 2d array, but I'm figuring it's the exact same problem and this is just the most simple case.
Can anyone help me understand why it seems impossible to set anything but the first element here?
*Roomsize[roomIndex]
is the same as*(Roomsize[roomIndex])
. You want to say(*Roomsize)[roomIndex]
.(I'm assuming that
Roomsize
is actually aint**
. If that's not correct, then the problem may lie elsewhere.)