I have to read almost 1M of strings with 1's and 0's (i.e. 01111010) with same length and compare their Hamming Distance on C.
My idea is make something like this: Code #1
typedef struct _matrix
{
unsigned int n_rows;
unsigned int n_cols;
char ** mat;
} matrix;
matrix *create_matrix(matrix *mtrx)
{
//char** mat;
//matrix* mtrx = malloc(sizeof(matrix));
int x=10, y=10, i;
mtrx->mat = calloc(x+1, sizeof(char*));
for(i = 0;i<y;i++) mtrx->mat[i] = calloc(y+1, sizeof(char));
mtrx->n_rows = x;
mtrx->n_cols = y;
return mtrx;
}
int main()
{
matrix* mtrx = malloc(sizeof(matrix));
mtrx = create_matrix(mtrx);
int i;
for(i=mtrx->n_rows;i>=0;i--) free(mtrx->mat[i]);
free(mtrx->mat);
free(mtrx);
return 0;
}
This is gonna make a 10x10 matrix of char: 100bytes. Since I'll have binary strings I want to use only a bit for each element on the matrix instead of a byte. I just found about bit-fields but I'm don't understand sure how to use it to make code#1 use 100bits.
Saludos