I know I am making a simple mistake but I dont know what the problem here
#include <stdlib.h> #include <stdio.h>
[code]
int main(void)
{
FILE* fh;
char s[50];
int i;
int count =10;
double a,b;
printf("COUNT= %d", count);
fh=fopen("abc1.txt","r");
if (fh ==NULL){
printf ("Error opening file: abc1.txt");
}
for\(i=0; i< count; i\+\+\)\{
fgets\(s,49,fh\);
if\(feof\(fh\)\)\{
rewind\(fh\); //fclose\(fh\);previously doing like this
i--; //fh=fopen\("abc1.txt","r"\);previously doing like this
\}
\}
sscanf\(s,"%lf %lf\\n",&a,&b\);
printf\("VALUES :%f %f\\n", a, b \);
fclose\(fh\);
}
[\code]
suppose I ve txt file as below
abc1.txt
[code]
10.32 11.98
24.76 34.87
43 55
6 7
8 9
10 11
12 13
[\code]
I want If the counter value is 10 then it should display me the line 43 and 55 , but here it displays
24.76000 34.87000
I got the error I modified the code in bold .. Thanks..........
fh=fopen("abc1.txt","r");
if (fh ==NULL){
printf ("Error opening file: abc1.txt");
}
Is the code compiling alright? From the code you have posted it should dump because of how the input file is being specified specifically the code segment shown above. So how are you specifying the input filename to the compiled executable?
Actually I want to implement one function like below
It should read lines from a txt file until the function is called..
If the data from the txt file ends then it goes to the top and then again when the function is called it should display me the top row .. If the file pointer fh is already opened in another function fileopen();
I got stuck with fgets () & rewind() function .. Please need help..
Actually I am doing a like,
The function should read lines from a txt file until the function is called..
If the data from the txt file ends then it goes to the top and then again when the function is called it should display me the top row .. I am doing like below , But it's not doing what I am expecting