Good evening!
I need to output the first, third, fifth, and so on to the fifteenth real numbers to the console from the file. So far, I have only output all the lines from the file.
How can I output a certain text from a file?
Below are the commands executed on my terminal and their results:
:~/Документы/Cpp/projects$ vim test0.c
:~/Документы/Cpp/projects$ cat test0.c
Code:
#include<stdio.h>
void main(void)
{
FILE *file;
char str1[80];
char *str2;
file=fopen("dat.txt","r");
for(int i=0;i<17;i++)
{
str2=fgets(str1,sizeof(str1),file);
printf("%s",str1);
}
fclose(file);
}
:~/Документы/Cpp/projects$ gcc -o test0 test0.c
:~/Документы/Cpp/projects$ ./test0
Output:
0x7ffc2b05b698
0 9 11 4 1
7.5
5.8
7.2
4.2
4.5
7.3
1.7
1.5
8.0
0.6
3.9
7.0
3.0
2.8
7.2