I'm trying to read a file to extract numbers and then compare it to find the most used number.
Every time I run this, I get this msg in the debbuger (obviusly the program doesn't run).
Program received signal SIGSEGV, Segmentation fault.
In ?? () ()
I can't find the problem in my code, I deleted my file and the program runs, but when I put the "test" file this thing just crash...
#include <stdio.h>
#include <stdlib.h>
int main(){
FILE *fp;
int especie = 0;
int es = 0;
int noes = 0;
int i = 0;
fp = fopen("especies.txt", "r");
if (fp == NULL){
printf("\nError de apertura del archivo. \n\n");
}
else{
for (i; i <= 10000000000; i++){
while (feof(fp) == 0){
fscanf(fp, "%d", &especie);
if(i == especie){
es++;
}
else{
noes++;
}
}
if (es >= ((es+noes)/2)){
break;
}
else{
rewind(fp);
es = 0;
noes = 0;
}
}
printf("%d", i);
fclose(fp);
}
return 0;
}