Question: Write the function int strend ( s , t ) , which returns 1 if the string t occurs at the end of the string

Write the function int strend (s,t),which returns 1 if the string t occurs at the end of the string s,and returns zero otherwise. The provided program tests your function by first prompting the user for the string to search and then promoting the user for the string to search for. The program calls your strend() with the users input and displays a message indicating that the string was found or was not found. The strend() function must not print any information to the console. The only output from this program should be from the provided program.
The provided program:
#include
#include
///////////////////////////////////////////////////////
// CONSTANTS
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
// typedefs and structures
//////////////////////////////////////////////////////
///////////////////////////////////////////////////////
// globalVariables
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
// FunctionPrototypes
///////////////////////////////////////////////////////
int strend(char *s, char *t);
char* TrimRight(char* str, const char* trimChars);
/*****************************************************
*
* Function: main()
*
* Parameters:
*
* argc - main parameter for argument count
* argv - main parameter for argument values
*
******************************************************/
int main(int argc, char *argv[])
{
char baseString[1000];
char findString[1000];
// Obtain the string to search
printf("Enter a string: ");
fgets(baseString, sizeof(baseString), stdin);
TrimRight(baseString, NULL);
// Obtain the string to search for
printf("Enter string to search for: ");
fgets(findString, sizeof(findString), stdin);
TrimRight(findString, NULL);
// strend returns 1 if there is a match
if (strend(baseString, findString))
{
printf("Search string was found!!
");
}
else
{
printf("Search string was not found.
");
}
}
/*****************************************************
*
* Function: strend()
*
* Parameters:
*
* s - string to search
* t - string to search for
*
******************************************************/
int strend(char *s, char *t)
{
int retVal =0;
/* YOUR IMPLMENTATION GOES HERE */
return retVal;
}
/******************************************************************************
*
* TrimRight()
*
* Removes characters from the end of a string, defaults to whitespace
* characters is trimChars is null.
*
*****************************************************************************/
char* TrimRight(char* str, const char* trimChars)
{
int i;
if (trimChars == NULL)
{
trimChars ="\t
\v\f\r ";
}
i = strlen(str)-1;
while (i >=0 && strchr(trimChars, str[i])!= NULL)
{
str[i]='\0';
i--;
}
return str;
}
IN C.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!