473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Query reg file handeling..

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...
Apr 29 '09 #1
2 1473
donbock
2,426 Expert 2GB
@shariquehabib
It all depends on the format of row.txt. The data format must include some sort of row delimiter. A simple approach would be to scan the file and count those delimiters. A more complex approach would involve verifying that there is no malformed or otherwise invalid data in the file.
Apr 29 '09 #2
weaknessforcats
9,208 Expert Mod 8TB
Why bother. Use a linked list and just keep adding nodes to the linked list as you read records from the disc file.
Apr 29 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marc Cromme | last post by:
I would like to ask a question about (good ?) style and possibilities in mixing C FILE* and C++ file streams. The background is that I want to use the C libpng library from within C++, but I...
4
by: deko | last post by:
When using OutputTo with a query, the 'File name' window in the 'Output To' dialog gets populated with the name of the query by default. This makes the exported file self-describing if the query...
3
by: Kbalz | last post by:
I have a Form that is performing a wizard-like step system (using TabControl), and I need a key combination (like ControlKey + A + T) to be caught and show a secret admin TabPage. I tried to add...
17
by: NeoAlchemy | last post by:
I am starting to find more web pages that are using a query parameters after the JavaScript file. Example can be found at www.opensourcefood.com. Within the source you'll see: <script...
1
tolkienarda
by: tolkienarda | last post by:
hello wonderful people of java land i am writing a program and trying to check to make sure some of my inputs are valid integers. i was told that i needed to read into exception handeling and now...
1
by: ashruba | last post by:
I want to read inbox of nokia N72 through file handeling in c/c++ please give guidence.
2
by: pankaj255143 | last post by:
i cannot get the output by using the function showdata()........plz run this code and send the solution on my ID <ID removed by weaknessforcats> // A PROGRAME TO OPERATE SOME FILE RELATED...
9
by: shariquehabib | last post by:
Hi All, I want to get some values by reading a file (already created) through file handeling but dont want to get DUPLICATE values. How can i do that..plz help me out....... E.g: file name...
4
by: shariquehabib | last post by:
Hi All, I am using file handeling in C lang. Can anyone please let me know that how can i read spaces from a perticular file?? To read some values (strings) i m using fscanf func. Can...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.