Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Reverse Write a program that inputs a C-String from the user and then reverses t

ID: 3535668 • Letter: R

Question


Reverse

Write a program that inputs a C-String from the user and then reverses the contents of the string. Your program should work by using two pointers. The "head" pointer should be set to the address of the first character in the string, and the "tail" pointer should be set to the address of the last character in the string (i.e. the character before the terminating null). The program should swap the characters referenced by these pointers, increment "head" to point to the next character, decrement "tail" to point to the second to last character, and so on, until all characters have been swapped and the entire string reversed.

Hint: Use strlen to calculate the address of the last character in the string. Loop until head &γτ;=tail. Use cin.getline to input a C-String.

Explanation / Answer

#include<stdio.h>
#include<conio.h>
void rev(char a[]);
main()
{
char s[30];
clrscr();
gets(s);
rev(s);
getch();
}
int i=0;
void rev(char a[])
{
if(a[i]=='')
return;
rev(a+(i+1));
printf("%c",a[i]);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote