hint: One function and use multiple times for double reverse.
Reverse entire string.
Parse whitespace, mark 1st and last character per word, then reverse that data, skip whitespace repeat!
have fun!
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
I see you're planning to give the drive some exercise!
May I suggest an alternative? Read the entire file iinto memory, then parse it in memory by working from end of load to beginning of load. Saves all that hard drive thrashing!
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
With that solution increase your buffer size slightly (Not too much as its recursion) and added an fopen() error check and don't forget your fclose().
Also note "rt" on the fopen() if you need your line terminator translation.
/r/n vs /n
wildgoose
Practically a Posting Shark
896 posts since Jun 2009
Reputation Points: 546
Solved Threads: 99
Salem
Posting Sage
11,531 posts since Dec 2005
Reputation Points: 5,862
Solved Threads: 953
. "rt" isn't portable.
Whatever gave you that idea? True, text mode is the default, but there is nothing wrong with specifying 't' in the mode string. If there was then it would be in the c standards.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
I believe it is undefined per the standard.
This is from n1124:7.19.5.3 The fopen function
3 The argument mode points to a string. If the string is one of the following, the file is open in the indicated mode. Otherwise, the behavior is undefined.231)
r open text file for reading
w truncate to zero length or create text file for writing
a append; open or create text file for writing at end-of-file
rb open binary file for reading
wb truncate to zero length or create binary file for writing
ab append; open or create binary file for writing at end-of-file
r+ open text file for update (reading and writing)
w+ truncate to zero length or create text file for update
a+ append; open or create text file for update, writing at end-of-file
r+b or rb+ open binary file for update (reading and writing)
w+b or wb+ truncate to zero length or create binary file for update
a+b or ab+ append; open or create binary file for update, writing at end-of-file[edit]Ah, but C90 had more wiggle room: The argument mode points to a string beginning with one of the following sequences:103
"r" open text file for reading "w" truncate to zero length or create text file for writing "a" append; open or create text file for writing at end-of-file "rb" open binary file for reading "wb" truncate to zero length or create binary file for writing "ab" append; open or create binary file for writing at end-of-file "r+" open text file for update (reading and writing) "w+" truncate to zero length or create text file for update "a+" append; open or create text file for update, writing at end-of-file "r+b" or "rb+" open binary file for update (reading and writing) "w+b" or "wb+" truncate to zero length or create binary file for update "a+b" or "ab+" append; open or create binary file for update, writing at end-of-file
103 Additional characters may follow these sequences.
[edit=2]And n1124's footnote was231) If the string begins with one of the above sequences, the implementation might choose to ignore the remaining characters, or it might use them to select different kinds of a file (some of which might not conform to the properties in 7.19.2).
[edit=3]I just avoid it.
Dave Sinkula
long time no c
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314