I´m new in C programming and have a problem I cant solve.
From a file with a lot of information, structured like
"id" \t 2048 times '0' or '1'
e.g.:
81283 \t 0101011010.....0110
I've to find, from a new sequence introduced by the user, the 3 most similar elements with the same size of the sequence introduced by the user.
E.g. sequence introduced by user, 010101, the program has to show like
- n1= 010101
- n2= 010100
- n3= 010010
Those are the 3 most similar sequences from all the 2048 '0' '1' in each line.
I hope that the problem was well explain. I have this code below, but it does not solve the problem.
Can anyone help me?
Thanks.
int procura(int *v, int *c, int tam){
int i,j,t;
FILE *fp;
fp=fopen("fich.txt","r");
v=(int*)malloc(sizeof(int));
c=(int*)malloc(sizeof(int));
while(!feof(fp)){
fscanf(fp,"%d",&v);
}
t = sizeof(v)/sizeof(*v);
for(i=0;i<tam;i++){
for(j=0;j<t;j++){
if(c[i]==v[j])
return 1;
else
return 0;
}
}
}
int main(){
int *v, *c;
int i,tam,a;
printf("array size\n");
scanf("%d",&tam);
c=(int*)malloc(tam*sizeof(int));
printf("Seq\n");
for(i=0;i<tam;i++){
scanf("%d",&c[i]);
}
printf("%d",procura(v,c, tam));
return 0;
}