I have this function that saves in an integer variable all the numbers from a text file. But I want to make a change so that I can save just the second number in each line into a vector and then print the whole vector. Here is an example of the file.txt
:
123 19
321 18
432 9
876 16
875 17
And here is the code that must be changed:
void LerVetor(int *V, int *N)
{
FILE *fp;
int marks;
fp = fopen("dados3.txt", "r");
if (fp == NULL)
printf("Falha ao abrir ficheiro\n");
rewind(fp);
do
{
fscanf(fp, "%d", &marks);
printf("%d\n", marks);
} while (!feof(fp));
fclose(fp);
}
The output is the same as the file.txt
because the code just prints the content of the file.
Resume: Save just the second numbers of each line, ex: 19
, 18
, 9
..., in a vector and then print the vector.