Question: ------------------------------------------------------------------------------------------------------------- lab4a . c. #include #define MAX_SIZE 500 void myStrInput ( char *s ); int myStrCmp( char *s1, char *s2 ); main() { char strg1[

 ------------------------------------------------------------------------------------------------------------- lab4a . c. #include #define MAX_SIZE 500 void myStrInput (

-------------------------------------------------------------------------------------------------------------

lab4a . c.

#include #define MAX_SIZE 500 void myStrInput ( char *s ); int myStrCmp( char *s1, char *s2 ); main() { char strg1[ MAX_SIZE ], strg2[ MAX_SIZE ]; /* Input strings strg1 and strg2. */ /* Assume that the length of each input string is less than 100 characters. */ myStrInput( strg1 ); myStrInput( strg2 ); printf( "%d ", myStrCmp( strg1, strg2 )); } /************* DO NOT MODIFY ANYTHING ABOVE THIS LINE, *************/ /************* EXCEPT THE HEADER CONTAINING YOUR INFO **************/ /* Function myStrInput Input: an array of char pointed to by pointer s. Output: the same array that stores the user's input string. Note: The length of each input string is less than the array size. So no error checking for the string length is required. Do not modify the function definition. */ void myStrInput ( char *s ) { /* Add your code here. */ /* Do not use array indexing. */ /* You may define additional variables, except arrays. */ /* Do not use any C library functions, except getchar(). */ } /* Function myStrCmp Input: two strings pointed to by pointers s1 and s2. Output: returns the first position (array index) where the two strings differ. Special cases: 1. Two strings are equal: returns -1. 2. One string is a substring of the other (e.g., "CSE2031" and "CSE2031E3.0"): returns the length of the shorter string. Do not modify the function definition. */ int myStrCmp( char *s1, char *s2 ) { /* Add your code here. */ /* Do not use array indexing. */ /* You may define additional variables, except arrays. */ /* Do not use any C library functions. */ }

A.1 Specification Write a C program that contains two functions, one to input two non-empty strings and the other to compare them. The comparison returns an integer that indicates the first position (array index) where the two strings differ. A.2 Implementation The program to be submitted is named lab4a.c. Use the given template lab4a.c and fill in your code. Submit only file lab4a. c. The first function to be implemented is myStrInput(). See file lab4a.c for its specification. Use getchar and a loop to read a line of characters, and store the input characters into the array. The loop terminates when a new line character ' ' is entered. The new line character ' ' is NOT part of the line (i.e., discard the new line character' '). The second function to be implemented is myStrcmp(). See file lab4a.c for its specification. The function returns an integer that indicates the first position (array index) where the two strings differ. Consider the following two special cases: o Two strings are equal. In that case the return value is -1. o One string is a substring of the other (e.g., CSE2031 and CSE2031E3.0). In that case, the return value is the length of the shorter string (i.e., the index of the null character in the shorter string) In both functions, do not use array indexing such as s[i]. Use only pointers and address arithmetic to manipulate the array elements. If you use array indexing in your code, your program will not be marked and given zero point. Hint: Write and test your program using array indexing first, then "translate" array accesses to pointers. . Do not modify the function definitions in file lab4a.c. A.3 Sample Inputs/Outputs indigo 51 % a.out This is CSE2031. CSE2031E3. indigo 54 % a. out I'll go now. I will go soon. indigo 49 % a. out This is 2031. This is 2011. 10 indigo 50 % a. out abc abc indigo 52 % a. out CSE2031 CSE2031E3.0 indigo 53 % a. out It is going to snow tomorrow. It is going to rain tonight. 15

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!