76 249
Assignments Done
98,5%
Successfully Done
In May 2019

Answer to Question #49935 in C++ for yolanda

Question #49935
(USING CODEBLOCKS)
Write a program that given two character strings from the user:
 Checks these two character strings to see if one string is the reverse of the other.
 If the strings are reverse, display: “Reverse Strings Found”, otherwise display: “Reverse Strings Not Found”.
 Create a function to perform this task.
Expert's answer
#include <stdio.h>
#include <cstdlib>
using namespace std;
int revCheck( char *s_1, char *s_2 )
{
int length = 0;
while ( *s_2 != '\0' ) /* loop sets the pointer of 2th string to the end of the string*/
{
s_2++;
}
s_2--; /* exclude '0' */
while ( *s_1 != '\0' ) /* reverse check loop */
{
if ( *s_1 != *s_2 ) /* continue loop until the first mismatch occurs */
{
printf("Reverse String Not Found\n");
return 0; /* return from func */
}
s_1++; /* increment pointer of 1th string */
s_2--; /* decrement pointer of 2th string */
}

printf("Reverse String Found\n");
return 1;
}

int main()
{
char str_1[256]; /* string buffer 1th*/
char str_2[256]; /* string buffer 2th */
printf("Enter sentence 1th string: ");
gets(str_1); /* read string */
printf("Enter sentence 2th string: ");
gets(str_2); /* read string */
revCheck(str_1, str_2);
system("PAUSE");
return 1;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions