Hi,
I am using C language to read a file: row.txt
Can any one plz help me to get number of rows present in a file BEFORE reading a file.
So i can check number of rows and if the rows greater than the array size, i can throw an error.
I just wanted to check row numbers before fscanf function so we can come to know that how many rows are in row.txt file.
Please find my code:
#include <stdio.h>
typedef struct
{
int a;
int b;
}shane;
int main()
{
FILE *fp;
int row=0;
int i=0;
shane array[10];
fp=fopen("row.txt", "r");
if (fp ==NULL)
{
printf(" File: row.txt not found...\n");
}
printf("Rows are = [%d]\n",row);
while (fscanf(fp, "%d %d\n",&array[i].a,&array[i].b) != EOF)
{
i=i+1;
printf(" Row No:[%d] and Numbers are: [%d] [%d]\n",row,array[i].a,array[i].b);
}
printf("Rows are: [%d]\n", row);
}
PLease help me..:)
Thanks,
Sharique...