+ 1

How to reverse the order of words in a file using c (concept of file handling)

7th Jun 2019, 8:14 PM
Versha Mishra
Versha Mishra - avatar
6 Réponses
+ 1
https://code.sololearn.com/cluAUdoJVZMF/?ref=app OK made a few edits to make it work better in the code playground. Main thing is the rewrite of the while loop. Will not work for every input, but gives you a working starting point.
8th Jun 2019, 8:49 PM
Jared Bird
Jared Bird - avatar
+ 1
Thanks buddy!!! What I did is I just reverse the whole string then traverse till first space and then reverse that string again n same goes till the null character enters
12th Jun 2019, 3:15 PM
Versha Mishra
Versha Mishra - avatar
0
So "over the wall" would become. "wall the over", etc? There are multiple was to solve this. If the files aren't to big, then the easiest way would be to read the whole file into an array. Then search for spaces in the array from the end. Copy the words into a new array. Write the new array into a file. When you achieve this then you can think about how you want to handle punctuation.
7th Jun 2019, 11:25 PM
Jared Bird
Jared Bird - avatar
0
Ya!! I tried but didn't get the required output 😣
8th Jun 2019, 8:32 AM
Versha Mishra
Versha Mishra - avatar
0
Well you could post the attempt in the code playground, then we could see if there is an easy fix.
8th Jun 2019, 8:38 AM
Jared Bird
Jared Bird - avatar
0
Versha Mishra I thought it was more complex to do two reversals, but that obviously works.
13th Jun 2019, 10:39 AM
Jared Bird
Jared Bird - avatar