+ 1
How to reverse the order of words in a file using c (concept of file handling)
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.
+ 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
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.
0
Ya!! I tried but didn't get the required output 😣
0
Well you could post the attempt in the code playground, then we could see if there is an easy fix.
0
Versha Mishra I thought it was more complex to do two reversals, but that obviously works.