Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction Consider the string library function strcmp (s, t). In Java there is a similar method string.compareTo (s). This function determines if s lexicographically precedes

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Introduction Consider the string library function strcmp (s, t). In Java there is a similar method string.compareTo (s). This function determines if s lexicographically precedes t (i.e., if s appears earlier than t in dictionary). It does so by comparing the two strings character by Specification Implement your version of strcmp, called my_strcmp, which does the same comparison. Implementation Download file lab4strcmp.c. This program reads two strings from the user, calls library function strcmp to compare their lexicographical ordering, and then calls function my_stremp to compare the lexicographic ordering again. The program terminates when user enters two xxx. Implement function int my_strcmp (char []). Obviously, the function should not call library function strcmp. Note that your function doesn't have to return exactly the same value as strcmp -- it needs to return a value that has the same sign as those returned by strcmp. Complete the while loop so that it keeps on prompting user for inputs, and terminates when both two input strings are xxx, as shown in the sample output. Use function strcmp or my_strcmp to check. Sample input and output red 118 % a.out apple beast strcmp: "apple" appears earlier in dictionary than "beast" mystrcmp: "apple" appears earlier in dictionary than "beast" ace ave strcmp : "ace" appears earlier in dictionary than "ave" mystrcmp: "ace" appears earlier in dictionary than "ave" exit exam strcmp: "exit" appears later in dictionary than "exam" mystrcmp: "exit" appears later in dictionary than "exam" exam exam "exam" and "exam" are same "exam" and "exam" are same exam examine strcmp: exam" mystrcmp: "exam" appears earlier in dictionary than "examine" appears earlier in dictionary than "examine" examination exam strcmp: "examination" appears later in dictionary than "exam" mystrcmp: "examination" appears later in dictionary than "exam" xxx hello strcmp: "xxx" appears later in dictionary than "hello" mystrcmp: "xxx" appears later in dictionary than "hello" xxx XXX red 119 % #include #include #define SIZE 30 int main() { char a[SIZE); char b[SIZE); scanf("s", a); scanf("s",b); while int resu- strcmp(a,b); if (resu 0) printf("stramp: \"\" appears later in dictionary than \":\" ", a,b); else printf("\"\' and \"\" are same ", a, b); int resu2 - my_strcmp(a,b); if (resu2 0) printf("mystrcmp: "88" appears later in dictionary than \"\" ", a,b); else printf("\"os\" and "#s\" are same ", a,b); int my_strcmp(char all, char b){

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

More Books

Students also viewed these Databases questions

Question

2. What potential barriers would you encourage Samuel to avoid?

Answered: 1 week ago

Question

6. How would you design your ideal position?

Answered: 1 week ago