Hey there!
I'm trying to write a program in C++ that will read information in from a file and then tell the user how many strings are in the file and the lengths of the smallest and longest strings. I know I can figure out the length of the strings but I'm having trouble figuring out how to count the number of strings in a code. (It's probably really easy eh?)

Any help at all would be so awesome and greatly appreciated!

Thank you so much!!

Edited 4 Years Ago by Shaye12321: n/a

How is 'string' defined for this purpose? Technically any text file only has one string, the entire contents of the file. Another common method is reading words where a 'word' is any unbroken sequence of non-whitespace characters.

How is 'string' defined for this purpose? Technically any text file only has one string, the entire contents of the file. Another common method is reading words where a 'word' is any unbroken sequence of non-whitespace characters.

Exactly. A 'string' can be
- a single word
- a single line
- a sentence
- a paragraph
- a page
- entire file

Be explicit...

Exactly. A 'string' can be
- a single word
- a single line
- a sentence
- a paragraph
- a page
- entire file

Be explicit...

Sorry! The strings in question are single lines of no more than 30 characters.

well.. yeah.. but that doesnt work for everything..
Take a char variable and keep reading one one character from a file..
As soon as the character it reads is a space, increment a value of a variable, say i, by 1...
So in effect, what ur duin is counting spaces!!

After that.. the number of words in ur file are (No. of spaces + 1)

Example
Jason went to buy a loaf of bread

No. of spaces = 7
No. of words = 8 = No. of spaces + 1

P.S - That is the case for all sentences.. But yea, it wont work if u left no spaces between words like a smart ass :P !!

Comments
Best to read the thread and not post completely worthless information.

adityatandon, what part of

Sorry! The strings in question are single lines of no more than 30 characters.

did you not understand?

This article has been dead for over six months. Start a new discussion instead.