C programming ? (again. Doh!!!) :-(
by Michael Cozzolino · in Technical Issues · 03/27/2001 (8:07 am) · 2 replies
Ok I am working on a program with a group in class. We need to create a mini word processor. It needs to read in a text file and give the number of alphanumerics(able to do that :-) ) Total sentences and Total words. We are having a difficult time figuring out how to approach doing this. Help would be appreciated. Unfortunately we haven't learned anything about structs and some other things so if you give input, please be very basic (ie. nothing more advanced than arrays and pointers) as if you were telling someone that was knowlegeable but has not learned all of the concepts. Thank You.
About the author
Indie Developer in the Albany NY area. iOS, PC, Mac OSX development. http://itunes.apple.com/us/artist/michael-cozzolino/id367780489
#2
03/27/2001 (10:26 am)
I just got back from a meeting for our project. I think we have it down now. Our problem was figuring out how to determine a sentence. We had to take in account something in the text like Dr. or St. We have to look ahead in the text using a char array and if it's an alpha or punctuation and then space then it's a word. If it is a punctuation then a space then another space then it is a sentence.
Matthew King
Open up the text file (using fopen, fread, etc), and read it character by character. If you find a space or a comma, then that means a word just ended, so increment words. If you find a period, exclamation point, or question mark, that means a sentence just ended, so increment sentences.
You will have to watch out for numbers (which would have a decimal point).
I'll leave the implementation as an exercise for the reader. ;)