Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a C function which takes in two \"strings\" (pointers to bytes in memory w

ID: 3639806 • Letter: W

Question

Write a C function which takes in two "strings" (pointers to bytes in memory with a zero at the end), and returns a new string containing, in each position I. the maximum of the two characters at corresponding positions of the two input strings. If the two strings have different lengths, your result should have the length of the longer string, and all of the extra characters in the longer string will simply appear in the result at their original position.

Explanation / Answer

// This should work on Terminal. #include #include char C[100]; char* bigger (char A[],char B[]) { int i=0; while(A[i]!='' && B[i]!='') { if(A[i]>B[i]) C[i] = A[i]; else C[i] = B[i]; i++; } if(A[i]=='' && B[i]!='') { while(B[i]!='') { C[i] = B[i]; i++; } } else if(A[i]!='' && B[i]=='') { while(A[i]!='') { C[i] = A[i]; i++; } } C[i] = ''; return C; } int main() { char A[100],B[100]; printf(" Enter the first String : "); scanf("%s",A); printf(" Enter the second String : "); scanf("%s",B); strcpy(C,bigger(A,B)); printf(" Bigger String : %s",C); return 0; }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote