Hi I don't know why I get the segmentation fault error. I have to, given the pointer to a file (which contains one number per line, like 12232 in the first line and 240 in the second etc..) I have to find and print for each number the cipher that is repeated more in time in the number, line in 12232 it should printf: "the number is 12232 nad the number is 2"
void stampa(FILE *fp) {
char m[MAX], copia[MAX], *fp_m = m;
int rip, dim, i, j, massimo=0, valore;
if (fp == NULL){
printf("Puntatore a file vuoto.");
exit(0);
}
while(!(feof(fp))){
fgets(m, MAX, fp);
fp_m = m;
dim = strlen(m)-1;
for (i=0; i < dim; i++){
copia[i] = fp_m[i];
}
copia[i] = '\0';
for(i=0; copia[i]!='\0'; i++){
rip = 0;
if (copia[i] == '*')
i++;
else{
for(j=i; j < dim; j++){
if(fp_m[i] == copia[j]){
rip++;
copia[j] = '*';
}
}
if (rip == massimo && fp_m[i] > fp_m[valore])
valore = i;
if(rip > massimo){
massimo = rip;
valore = i;
}
}
}
massimo = 0;
printf("Il numero piu' ripetuto in %s e': %c \n", m, fp_m[valore]);
}
return ;
}