Helllo I was hoping to get some help, my function is not populating an array correctly, I have to take in a name a sting and then convert y or n to a 1 or 0 and store it. my function returns this:
Ritu010
N010
Larry000
n010
Dan010
y010
Judi000
y000
Eric010
y000
when it should be something like this:
Ritu Y N y
Larry n n y
Dan y y y
Judi n y n
Eric y y n
Isabelle y n y
Manisha y n n
Terra Y Y N
Dora n y n
Nick n n y
Code:
int readReviews (FILE * fptr, struct reviewStruct r[NUMBER_REVIEWERS]){
char ch;
int i=0;
while(!feof(fptr)){
fscanf(fptr,"%s",r[i].reviewer);
for (int j= 0; j < NUMBER_MOVIES; j++){
fscanf(fptr,"%c",&ch);
if (ch == 'y') {
r[i].feedback[j] = 1;
}
else if(ch=='Y'){
r[i].feedback[j] = 1;
}
else if(ch=='n'){
r[i].feedback[j] = 0;
}
else if (ch=='N'){
r[i].feedback[j] = 0;
}
}
i++;
}
return 1;
}
question from:
https://stackoverflow.com/questions/65947363/fscanf-not-reading-file-correctly 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…