I'm currently trying to create a 320x240 array for an image but the pixels are sent by line(320 at a time). And so I thought about just running a loop that counts 240 so that at each count I insert my smaller array[320] to that of the bigger array[240][320]
here is the code I've done so far.
int main()
{
int mi,mj,this;
while(this < 240)
{
decodeHex(stringToDecode,hexValues);
compile(this,hexValues);
this=this+1;
}
for(mi = 0; mi < 240; mi=mi+1)
{
printf("\npctureArray [%d][%d]\n",mi,320);
for(mj=0; mj < 320;mj=mj+1)
{
printf("%lx",pictureArray[mi][mj]);
}
}
return 0;
}
void decodeHex(char * encodedString,unsigned long * hexConverted)
{
int i;
unsigned long offset = 0x41;
for(i=0;i<strlen(encodedString);i = i+3)
{
*hexConverted = (((unsigned long)encodedString[i]- offset) << 8) | (((unsigned long)encodedString[i+1] - offset) << 4) | ((unsigned long)encodedString[i+2] - offset);
hexConverted = hexConverted + 1;
}
}
void compile(int i,unsigned long * ptr)
{
int j;
for(j= 0;j<320;j=j+1)
{
pictureArray[i][j] = (unsigned long)*(ptr+j);
}
}
the decoder part of the code receives a char array[960] and so it is converted to unsigned long array[320] <--- 960/3 = 320 RGBs
I'm confused as to why my code has segmentation error. Can anyone take a peek and tell me if there's something I'm missing here
Set the intial value of this
.
this = 0;
Without initialization, this
will not be containing 0
.