C program files This is a program to reverse first N characters in a file But this program is not reversing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

C program files This is a program to reverse first N characters in a file But this program is not reversing

first we need to open a file named “TestDataFile3.txt” in read or write mode then write the content on the file. Then read the number of characters to copy. copy the specified number of characters into a string then reverse the string over write the entire string into the files from the beginning then close the file open the copied file in read mode read the text from the file and print on the screen and close the file But it is not reversing https://code.sololearn.com/c30ns70grCHX/?ref=app

9th May 2021, 12:53 PM
Bharani Kudala
Bharani Kudala - avatar
1 Answer
+ 3
void stringReverse(char data[100]) { char temp; int l=0,n; n=strlen(data) - 1; // here is your fix. Add the - 1. while(l<n) { temp=data[l]; data[l]=data[n]; data[n]=temp; l++; n--; } } You were getting no output because the implicit '\0' was going to [0] in your attempt at reversing the string. The - 1 will start one character earlier.
9th May 2021, 2:24 PM
Josh Greig
Josh Greig - avatar