Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advanced Oracle Solaris 11 System Administration

Authors: Bill Calkins

1st Edition

0133007170, 9780133007176

More Books

Students also viewed these Databases questions