Hello everyone. My questions are the following:
1) In a program, different values to a vector are given(e.g.: vector[1]=3; vector[2]=5; ...)
Declaration: int vector[5]={1,5,6,7,2};
And at the time of saving the info into a text file it would be something like this:
Code:
fprintf(fp,"%d %d %d %d", vector[1], vector[2], vector[3], vector[4])
and the fscanf:
Code:
fscanf(fp,"%d %d %d %d", &vector[1], &vector[2], &vector[3], &vector[4])
Imagine that it is a longer vector, then it would be a mess.
Can there be written something like this?:
Code:
fprintf(fp,"%d %d %d %d", vector[i])
fscanf(fp,"%d %d %d %d", &vector[i])
2) I've heard around that there is a command or statement used to find values in a vector. Maybe:
Code:
while(5 in vector){printf("There is a 5 in the vector.");}
But couldn't figure out how this is. Any help would be apreciated, if something isn't clear tell me, thanks.