Below is my code:
#include <stdio.h>
#include <math.h>
void main () {
int my_data[4][500];
int myDataBinary[500] = {0};
int index1 =0;
my_data[0][1] = 1;
my_data[0][3] = 3;
my_data[0][5] = 9;
my_data[0][4] = 10;
for(int i=0; i<sizeof(my_data)/sizeof(int);i++)
{
if(my_data[0][i] > 0){
index1 = my_data[0][i];
myDataBinary[index1] = 1;
printf("my data %d = %d\n",index1,myDataBinary[index1]);
}
}
}
The o/p i see is:
my data 1 = 1
my data 3 = 1
my data 10 = 1
my data 9 = 1
Bus error
I guess this error at the end is because of the sizeof that I use in the “for loop”. I want to run my loop only for those values inside my two dimensional aray. Any idea where i am going wrong.
Instead of this:
You probably want: