I am trying to load elements into an array using a function but I don't know what I'm doing wrong. I want to load elements from a data file until -1 is entered. Here is what I have and I don't know what to do from here.
#include <stdio.h>
/*Function to scan in grades*/
int LoadArray (int grade[ ])
{
int i = 0;
while(scanf("%i", grade[i]) != -1) {
i++;
}
return i;
}
/*Main program*/
int main (void)
{
int grade[200], count=0;
/*Call function*/
count = LoadArray(grade);
printf("%i", count);
return 0;
}
scanf(and family) reference, pay close attention to the argument types in the format-code table (this is really important!).scanf()would return-1at some point? is tEOFthat you mean?;!while(i < 200 && 1==scanf("%i", &grade[i]) && grade[i] != -1) {