jaredgalen
Programmer
I'm new to C, today being my first day really.
Here's the prob:
BYTE indexes[11]; <-- putting ints between zero and 4096 into this array.
In one hand I have a variable X.
I'm looking at indexes[0], I want to I push everything down and put X in at indexes[0].
However, somehow X is getting changed.
Before reordering - Inserting X=3236 <-variable X
225 161 98 164 225 161 100 96 37 36 33
X=164<- variable X has changed to this, somehow
After reordering
164 225 161 98 164 225 161 100 96 37 36
164 is what indexes[0] contains now, it should be 3236.
Should I be using pointers or something?? I really haven't a clue, this whole 'C' thing is very confusing.
What am I missing or have a made a really silly mistake that I just can't see....
Here's the bit of source that corresponds to this, there is only a print statement between...
The code is really crappy I know, I don't really know any major functions so it's very basic.
for(i=0;i<4096;i++)
{
if(keyCounter>largestKeyCount)
{
printf("\nBefore reordering - Inserting "
printf("%d",i);
printf("\n"
for(j=0;j<11;j++)
{
!!XXXX Here it has the right value XXX!!
printf("%d",indexes[j]);
printf(" "
}
tempIndex1 = indexes[0];
indexes[0] = i;
printf("\n"<-!!XXXX Here it has changed XXXX!!
printf("%d",indexes[0]);
for(j=1;j<11;j++)
{
tempIndex2 = indexes[j];
indexes[j] = tempIndex1;
tempIndex1 = tempIndex2;
}
printf("\nAfter reordering\n"
for(j=0;j<11;j++)
{
printf("%d",indexes[j]);
printf(" "
}
}
Hope someone can help me.
Thanks
jG
Here's the prob:
BYTE indexes[11]; <-- putting ints between zero and 4096 into this array.
In one hand I have a variable X.
I'm looking at indexes[0], I want to I push everything down and put X in at indexes[0].
However, somehow X is getting changed.
Before reordering - Inserting X=3236 <-variable X
225 161 98 164 225 161 100 96 37 36 33
X=164<- variable X has changed to this, somehow
After reordering
164 225 161 98 164 225 161 100 96 37 36
164 is what indexes[0] contains now, it should be 3236.
Should I be using pointers or something?? I really haven't a clue, this whole 'C' thing is very confusing.
What am I missing or have a made a really silly mistake that I just can't see....
Here's the bit of source that corresponds to this, there is only a print statement between...
The code is really crappy I know, I don't really know any major functions so it's very basic.
for(i=0;i<4096;i++)
{
if(keyCounter>largestKeyCount)
{
printf("\nBefore reordering - Inserting "
printf("%d",i);
printf("\n"
for(j=0;j<11;j++)
{
!!XXXX Here it has the right value XXX!!
printf("%d",indexes[j]);
printf(" "
}
tempIndex1 = indexes[0];
indexes[0] = i;
printf("\n"<-!!XXXX Here it has changed XXXX!!
printf("%d",indexes[0]);
for(j=1;j<11;j++)
{
tempIndex2 = indexes[j];
indexes[j] = tempIndex1;
tempIndex1 = tempIndex2;
}
printf("\nAfter reordering\n"
for(j=0;j<11;j++)
{
printf("%d",indexes[j]);
printf(" "
}
}
Hope someone can help me.
Thanks
jG