C code is given below:
#include<stdio.h>
// read line function
int readline(char str[],int maxchar) {
char ch;
int ind = 0; // for calculating the length
scanf("%c",&ch);
while(ind<40 && ch!='\n') { // this will
read the characters until a newline is entered
str[ind] = ch;
scanf("%c",&ch);
ind++;
}
return ind; // the ind will be the length of the
string
}
// for finding the match
char* findmatch(char pattern[], char text[],int patternlength, int
textlength) {
for(int i=0;i<=(textlength-patternlength);i++) { //
we go to the last possible index of match which is
(textlength-patternlength)
if((pattern[0] == '?')||(text[i] ==
pattern[0])) { // if the fist char of pattern match or it is a
wildcard then there can be a match
int j = 0, k =
i;
for(;(j<patternlength) && (k<textlength);j++,k++) {//
now we match character by character
if(pattern[j] == '?') // if there is a wildcard
in pattern, it's okay
continue;
else if(pattern[j] != text[k]) { // otherwise if
it does not match then no match
break;
}
}
if(j ==
patternlength) // if we traversed whole pattern it means it did not
break, which means there is a match at index i.
return &text[i]; // so return address of
match
}
}
return NULL; // otherwise return null
}
void printmessage(char *position, char text[],int patternlength,
int textlength) {
if(position == NULL)
printf("no match\n");
else {
int ind = (position - text); //
index will be the difference of base address and address of
match
printf("The pattern was found at
char %d. ",ind + 1);
printf("The remaining text chars
are: ");
ind += (patternlength); // go to
the end of match
while(ind<textlength) {
printf("%c",text[ind]); // printing the chars after match
ind++;
}
printf("\n");
}
}
int main() {
char text[40], pattern[40], *position;
int textlength, patternlength;
printf("Enter text: ");
textlength = readline(text, 40);
printf("Enter Pattern: ");
patternlength = readline(pattern, 40);
position = findmatch(pattern, text, patternlength,
textlength);
printmessage(position, text, patternlength,
textlength);
}
Sample input and output:
Screenshot of the code is given below:

If the answer helped please upvote, it means a lot and for any query please comment.
Download the file patternMatch.c from the course website. This file contains part of a program to...
Write a program **(IN C)** that displays all the phone numbers in a file that match the area code that the user is searching for. The program prompts the user to enter the phone number and the name of a file. The program writes the matching phone numbers to the output file. For example, Enter the file name: phone_numbers.txt Enter the area code: 813 Output: encoded words are written to file: 813_phone_numbers.txt The program reads the content of the file...
IN C language Write a C program that prompts the user to enter a line of text on the keyboard then echoes the entire line. The program should continue echoing each line until the user responds to the prompt by not entering any text and hitting the return key. Your program should have two functions, writeStr andcreadLn, in addition to the main function. The text string itself should be stored in a char array in main. Both functions should operate...
Write a program, called wordcount.c, that reads one word at a time from the standard input. It keeps track of the words read and the number of occurrences of each word. When it encounters the end of input, it prints the most frequently occurring word and its count. The following screenshot shows the program in action: adminuser@adminuser-VirtualBox~/Desktop/HW8 $ wordCount This is a sample. Is is most frequent, although punctuation and capitals are treated as part of the word. this is...
Part1. Write a C program contains the following declarations: char customer_name[N_CUSTOMERS][MAX_NAME_LENGTH]; int customer_number[N_CUSTOMERS] A program uses a text file that contains the following data on each line: The customer number is an int, and the first and last names are alphabetic strings that contain no whitespace. The last and first names themselves are however separated by whitespace. Write a C function with the following prototype: void read_customer (char name[][MAX_NAME_LENGTH], int number[], int position, FILE *cust_file) Your function should read a...
Write a function called char_counter that counts the number of a certain character in a text file. The function takes two input arguments, fname, a char vector of the filename and character, the char it counts in the file. The function returns charnum, the number of characters found. If the file is not found or character is not a valid char, the function return -1. As an example, consider the following run. The file "simple.txt" contains a single line: "This...
Please Complete the following C Code with Comments explaining your solution and post a screenshot of it working. Summary: This project explores pattern matching techniques to find a pattern in a DNA sequence containing letters in the DNA alphabet {A, C, G, T}. For example, suppose we have a DNA sequence as follows: ATGACGATCTACGTATGGCAGCCACGCTTTTGATGTTAAGTCACACAGCCAAGTCA ACAAGGGCGACTTCATGATCTTTCCGCTCCGTTGGTGTAGGCCCGTGTTCAAATTC AATGGCTGATTGGAATTACCTTTGAAATACTCCAACCGACCGCCACGGCCAGGGT CCCGCTCGCTCTCTGTGGCCCTCCCACAAAACTCCGGTGAAAGTTGATTTGGACAC GGACCCAAAGCAGCGTAGATTATTCGAGCGTATTCGGTAGTCATTGAGGCCCCAA The pattern “AATGG” can be found at the beginning of the third line. Note that overlapping matches are counted individually. For example,...
1. You are given a C file which contains a partially completed
program. Follow the instructions contained in comments and complete
the required functions. You will be rewriting four functions from
HW03 (initializeStrings, printStrings, encryptStrings,
decryptStrings) using only pointer operations instead of using
array operations. In addition to this, you will be writing two new
functions (printReversedString, isValidPassword). You should not be
using any array operations in any of functions for this assignment.
You may use only the strlen() function...
Write a C program that takes two sets of characters entered by the user and merge them character by character. Enter the first set of characters: dfn h ate Enter the second set of characters: eedtecsl Output: defend the castle Your program should include the following function: void merge(char *s3, char *s1, char *s2); The function expects s3 to point to a string containing a string that combines s1 and s2 letter by letter. The first set might be longer...
Write a program that replace repeated three characters in a string by the character followed by 3. For example, the string aabccccaaabbbbcc would become aabc3ca3b3cc. When there are more than three repeated characters, the first three characters will be replaced by the character followed by 3. You can assume the string has only lowercase letters (a-z). Your program should include the following function: void replace(char *str, char *replaced); Your program should include the following function: void replace(char *str, char *replaced);...
Write a function called char_counter that counts the number of a certain character in a text file. The function takes two input arguments, fname, a char vector of the filename and character, the char it counts in the file. The function returns charnum, the number of characters found. If the file is not found or character is not a valid char, the function return -1. As an example, consider the following run. The file "simple.txt" contains a single line: "This...