Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

modify the program to read 3 lines of input, then print the line with the most occurrences of t[] and how many there are. Please

modify the program to read 3 lines of input, then print the line with the most occurrences of t[] and how many there are. Please try not to add any functions and just modify what is given. Thank you!

#include #define MAXLINE 1000 char pattern[] = "ould";

// getline get a line store it in s - return the size of the read line int getline2(char s[], int lim) { int c, i; //c is char , i is the counters for(i = 0; i < lim-1 && (c = getchar()) != ' '; ++i) { s[i] = c; } s[i] ='\0'; //append the null terminator return i; //return the size }

//function will search the input array for the term array //if we find the term, return the first index of the term within the array //if we dont find the term return -1 flag int strindex(char s[], char t[]) //s input, t term { int i, j, k;

for(i = 0; s[i] != '\0'; i++) //search the array and keeps our place! { for(j = i, k = 0; t[k] !='\0' && s[j] == t[k]; j++ , k++)//j searches where we are starting with i in s, k searches t ; //search for a match!!! if( k > 0 && t[k] == '\0') //if we found a match return i; }

return -1;

} int main() { char line[MAXLINE];

while(getline2(line,MAXLINE) > 0) //keep reading lines until empty line is entered { if(strindex(line,pattern) >= 0) //returns -1 if there is no match printf("%s ", line); }

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Web Database Development Step By Step

Authors: Jim Buyens

1st Edition

0735609667, 978-0735609662

More Books

Students also viewed these Databases questions

Question

=+ 6. A Case Study in this chapter concludes that if

Answered: 1 week ago