LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   File Input, how to get number of items? (https://www.linuxquestions.org/questions/programming-9/file-input-how-to-get-number-of-items-300217/)

ftgow 03-10-2005 09:59 PM

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.

jschiwal 03-11-2005 01:31 AM

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.


All times are GMT -5. The time now is 08:47 AM.