LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-10-2005, 09:59 PM   #1
ftgow
Member
 
Registered: Aug 2003
Distribution: Slackware
Posts: 69

Rep: Reputation: 15
File Input, how to get number of items?


I have a file to input into one of my C++ programs. I can get input and all that, but I was wondering if it is possible to take the file and get the number of items (each item is seperated by whitespace) and put that into a variable. The variable and the data in the array is all of type int.

THank you.
 
Old 03-11-2005, 01:31 AM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Do you mean without reading the data? If the data is of fixed size, you could calculate the number of items from the size. If the data ends with a newline, then divide the size by the item size +1.
Or you could precede the file with metadata containing the number of items.
Another option is to read up to a sentinel and have the count after the sentinel. Then you could position the file pointer at an offset from the end of the file and read just the count.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Creating Linked Lists from items in a file SeniorSE Programming 5 09-14-2005 10:53 PM
How to limit number of items in .recently-used neo_in_matrix Linux - Newbie 2 06-09-2005 11:04 AM
Having rm or mv take file input BlueOrb Linux - Newbie 4 06-29-2004 09:42 PM
terminal items to file g00ral Linux - General 2 05-09-2004 05:39 AM
input from a file ?? FredrikN Programming 5 03-30-2002 12:53 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:31 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration