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

This problem is about c code for Microsoft visual studio. It can be found by fol

ID: 647732 • Letter: T

Question

This problem is about c code for Microsoft visual studio. It can be found by following two links(indluding two images):

https://drive.google.com/file/d/0B7WUYmW3LyL6cEJSWHFuOHFqdVE/view?usp=sharing

https://drive.google.com/file/d/0B7WUYmW3LyL6N0FXQmx1WXUtOFk/view?usp=sharing

This is how I start it:

#define _CRT_SECURE_NO_WARNINGS
#include
#include
#define len 100


void FindStringSegment(){

}

int main(void) {
   printf("Input a string to find with the test string: ");

  

   return(0);
}

please help me complete it based on this format.

Explanation / Answer

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define len 100


int FindStringSegment(char str[], char str1[], int s){
   int i, j;
   for (i = s; i <= strlen(str) - strlen(str1); ++i){
       int flag = 0;
       for (j = i; j < (i + strlen(str1)); ++j){
           if (str[j] != str1[j - i]){
               flag = 1;
           }
       }
       if (flag == 0){
           return i;
       }
   }
   return -1;
}

int main(void) {
   int size = len;
   char ch;
   int count1 = 0, count2 = 0;
   char str[len];
   char str1[len];
   printf("Input a string to find with the test string: ");
   do{
       scanf_s("%c", &ch, 1);
       if (ch == ' '){
           str[count1] = '';
           break;
       }
       else{
           str[count1++] = ch;
       }
   } while (1);
   printf("Input a string to find within the test string: ");
   do{
       scanf_s("%c", &ch, 1);
       if (ch == ' '){
           str1[count2] = '';
           break;
       }
       else{
           str1[count2++] = ch;
       }
   } while (1);
   printf("The test string is: %s ", str);
   int s = 0;
   while (1){
       int ind = FindStringSegment(str, str1, s);
       if (ind == -1){
           break;
       }
       else{
           printf("%s found at column %d ", str1, ind);
           s = ind + 1;
       }
   }
   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