Pretty much have to implement pattern_match to form a restricted \"grep\". Just
ID: 3529397 • Letter: P
Question
Pretty much have to implement pattern_match to form a restricted "grep". Just need to implement a few special characters which include: . (period) Matches any character. ? (question mark) The preceding character may or may not appear in the line. (backslash) "Escapes" the following character, nullifying any special meaning it has Examples of this being used are ?: a question mark must appear in the line they?re: Matches a line that contains either the string "theyre" or the string "there" h.d..?n: matches lines that contain substrings like "hidden", "hidin", "hbdwen", "hadbn", etc. cu.?t: matches lines that either contain the substring "cut" or "cu.t" You may assume that the code will not be run against patterns that don't make sense, like "hello??" and "?oops". Please do not modify the skeleton code. You may add whatever support functions, types, variables, whatever you want, but please keep the code that appears in the skeleton intact. So yeah...here's the code! :) #include #include #define MAXLINE 256 char *progn; void usage(void) { fprintf(stderr,"Usage: %s pattern ",progn); } int pattern_match(char *pattern, char *str) { // implement me } int main(int argc, char **argv) { char line[MAXLINE]; char *pattern; progn = argv[0]; if(argc!=2) { usage(); return EXIT_FAILURE; } pattern = argv[1]; while(!feof(stdin) && !ferror(stdin)) { if(!fgets(line,sizeof(line),stdin)) { break; } if(pattern_match(pattern,line)) { printf("%s",line); } } if(ferror(stdin)) { perror(progn); return EXIT_FAILURE; } return EXIT_SUCCESS; }Explanation / Answer
sory actually it is tough to read and what is your asking exactly?
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.