I am reading data from a file and writing it into an array. This works but I can't seem to read it back out of the array properly. Where is the mistake?
int main(){
struct mountain{
char name[300];
char height[5];
};
struct mountain mountainArray[8];
fp = fopen("berge.txt", "r");
if(fp == NULL) {
perror("Error opening file");
return(-1);
}
int i=0;
while ( fgets(readLine, buflen, fp)){
if(i<8){
char * p;
p = strtok (readLine,":");
if (p != NULL){
strcpy(mountainArray[i].name,p);
p = strtok (NULL, ":");
if (p != NULL)
strcpy(mountainArray[i].height,p);
}
i++;
}
}
unsigned int f;
for (f=0; f<8; f++){
printf("%s\n", mountainArray[i].name);
}
fclose(fp);
return 0;
}