Create a program that includes a function called reverse tha

Create a program that includes a function called reverse that takes a string and returns a string in the reverse order. For example, given “hello” as the input, the function should return “olleh”, which is the reversed string of “hello”.

The main function should keep prompt the user to input a string until the user types “Q” For each string input call the function with the string and display the result. Note that the user input string may contain white spaces. Program Used: Visual Studios.

Test your program with the following input:

“Hello” (your program should display “olleH”)

“CBU” (your program should display “UBC”)

“C++ is fun!” (your program should display “!nuf si ++C”)  

“Q” (should exit the program)

Solution

#include<stdio.h>
#include <conio.h>
#include<string.h>


char * reverse(char *);

void main()
{
char str[20];
char option;
clrscr();


do
{
printf(\"\ Input a string \");
gets(str);

printf(\"\ reverse =%s\",reverse(str));

fflush(stdin);
printf(\"\ enter Q to quit\");
option=getche();

if(option==\'Q\')
break;


}while(1);

}

char * reverse(char *str)
{
char rev[50];
int i,k,j;
printf(\"\ %s\",str);

for(i = 0; str[i] != \'\\0\'; i++);
{
k = i-1;
}
for(j = 0; j <= i-1; j++)
{
rev[j] = str[k];
k--;
}
rev[j]=\'\\0\';

return rev;

}

Create a program that includes a function called reverse that takes a string and returns a string in the reverse order. For example, given “hello” as the input,
Create a program that includes a function called reverse that takes a string and returns a string in the reverse order. For example, given “hello” as the input,

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site