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

How to write a C program user defined function to check if a string contains a d

ID: 3923148 • Letter: H

Question

How to write a C program user defined function to check if a string contains a double letter in the middle, return 1 if it contains a double letter or 0 if it is not. For example, yellow, zipper, etc.... Ps: can't use <string.h> built-in function. How to write a C program user defined function to check if a string contains a double letter in the middle, return 1 if it contains a double letter or 0 if it is not. For example, yellow, zipper, etc.... Ps: can't use <string.h> built-in function.

Explanation / Answer

#include <stdio.h>
int stringCompare(char s[]){
   int i=0,mid_index=0;
   for(i=0;s[i]!='';i++)
  
   mid_index=(i-1)/2;
   if(s[mid_index] == s[mid_index+1 ] ||s[mid_index] == s[mid_index-1]){
       return 1;
   }
   return 0;
}
int main(void) {
   // your code goes here
   char s[200];
   scanf("%s",s);
   if(stringCompare(s)){
       printf("string contains a double letter in the middle");
   }
   return 0;
}

Input:

Yellow

Output:

Success time: 0 memory: 2172 signal: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