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

Write a Program in C that reads two strings (1000 characters). The program shoul

ID: 2247211 • Letter: W

Question

Write a Program in C that reads two strings (1000 characters). The program should work in Linux and wrote in C not C++. It should give a count for the Contain Count.

Contain case mean take the first string and match the second string to see if there is a o in the first that match the second (position doesn't matter). The contain nocase mean that it can be upper or lower case (postion doesn't matter). Must do it with all letter in string including spaces.

For example:

Books
Goblins


Output:


Contains: case:   3 nocase:   4

Explanation / Answer

#include<stdio.h>

char toLower(char ch) {
   if (ch >= 'A' && ch <= 'Z')
       ch = ch + 32;
   return ch;
}

int caseMatch(char *a, char *b) {
   int i, j;
   int count = 0;

   for (i = 0; a[i] != ''; i++)
       for (j = 0; b[j] != ''; j++)
           if (a[i] == b[j])
               count ++;
   return count;
}


int nocaseMatch(char *a, char *b) {
   int i, j;
   int count = 0;

   for (i = 0; a[i] != ''; i++)
       for (j = 0; b[j] != ''; j++)
           if (toLower(a[i]) == toLower(b[j]))
               count ++;
   return count;
}

int main() {
   char a[1000];
   char b[1000];
   int Case, noCase;
   printf("Enter 1st string: ");
   scanf("%[^ ] ",a);
   printf("Enter 2nd string: ");
   scanf("%[^ ] ",b);
   printf("a=%s b=%s ",a,b);
   Case = caseMatch(a,b);
   noCase = nocaseMatch(a,b);

   printf("Contains: case:   %d nocase:   %d ",Case,noCase);
}

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