Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#define _ CRT _ SECURE _ NO _ WARNINGS #include #include / * * * Determine if the string s starts with the string prefix.

#define _CRT_SECURE_NO_WARNINGS
#include
#include
/**
* Determine if the string s starts with the string prefix.
* @param s - the string to see if it starts with prefix
* @param prefix - the prefix to test
* @returns true if the strings begins with the prefix.
*/
int startsWith(const char s[], const char prefix[])
{
char buf[25]; int i;
int sz = strlen(prefix); for (i =0; i < sz; i++)
{
buf[i]= s[i];
}
buf[sz]='\0';
return 0== strcmp(buf, prefix);
}
/**
* Determine if the string s ends with the string suffix.
* @param s - the string to see if it ends with suffix
* @param suffix - the suffix to test
* @returns true if the strings ends with the suffix.
*/
int endsWith(const char s[], const char suffix[])
{
int sz = strlen(suffix); int slen = strlen(s);
return 0== strcmp(s + slen - sz, suffix);
}
int main(void)
{
char s1[]={ "upended" };
char prefix[]={"up"};
char suffix[]={"ed"};
printf("%s does %s start with %s
",
s1, startsWith(s1, prefix)?"" : " not", prefix);
printf("%s does %s end with %s
",
s1, endsWith(s1, suffix)?"" : " not", suffix);
return 0;
}

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

The Database Experts Guide To SQL

Authors: Frank Lusardi

1st Edition

0070390029, 978-0070390027

More Books

Students also viewed these Databases questions