Question

please implement this function by C languageWrite a string compare function which returns 1 if the strings match for n characters starting at offset m, O if the strings

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Below is the C language function:-

int submatch( char *s, char *t, int n, int m)

{

int l=0, k;

while( l < m)

{

if(s[l] == '\0' || t[l] == '\0') //then this means one of the string does not have length m

return 0; //Since no matching will be after index m

l++; //otherwise increment index l

}

while(s[l] != '\0' || t[l] != '\0') //we start with index following offset m, continue till one of the string does not end

{

if(s[l] != t[l]) //This means string does not match

return 0;

l++; //otherwise simply increment the index

}

if(s[l] == '\0' && t[l] =='\0') //This happens if both the strings s and t ends at the same time and being matched

return 1;

else

return 0;

}

Please comment for any clarification.

Add a comment
Know the answer?
Add Answer to:
please implement this function by C language Write a string compare function which returns 1 if the strings match for n characters starting at offset m, O if the strings don't match. You must chec...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In C Programming Language In this lab you will implement 4 string functions, two using array...

    In C Programming Language In this lab you will implement 4 string functions, two using array notation and two using pointers. The functions must have the signatures given below. You may not use any C library string functions. The functions are 1. int my strlen (char s ) - This function returns the number of characters in a string. You should use array notation for this function. 2. int my strcpy (char s [], char t I)- This function overwrites...

  • Write the following program in C Language using standard library functions. /*Implement the Find function, called...

    Write the following program in C Language using standard library functions. /*Implement the Find function, called in the program below. This function receives two strings, and looks for the first occurrence of the second string in the first string, returning the number of characters it is in, relative to the beginning of the first string. If not, returns -1. In the program, a string with two news headlines is given, and the sub-strings "iPad" and "Huawei” are searched for, having...

  • Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You...

    Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You will place all of your function prototypes in a header file named string utils.h and all of your function definitions in a source file named string utils.c. You should implement your own main test driver program to test your functions, but you need not hand it in. a. void addChar(char *str, char c, int n) - this function should add a char c at...

  • write program in C language. To get more practice working with files, you will write several...

    write program in C language. To get more practice working with files, you will write several functions that involve operations on files. In particular, implement the following functions 1. Write a function that, given a file path/name as a string opens the file and returns its entire contents as a single string. Any endline characters should be preserved char *getFileContents (const char filePath); 2. Write a function that, given a file path/name as a string opens the file and returns...

  • programming language is JAVA: We wish to implement a method  String insert(char c, String s) that returns...

    programming language is JAVA: We wish to implement a method  String insert(char c, String s) that returns a string with c inserted in the correct position in already sorted String s. To do so we will implement insert as follows: static  String insert(char c, String s) { return insertHelper(c, "", s); } static  String insertHelper(char c, String left, String right) {} // strip leading characters from right, & append to left 'till insertion point found. Now return left + c + right. For...

  • help me solving this both please in c++ language 6 Write function max(int al Lint n)...

    help me solving this both please in c++ language 6 Write function max(int al Lint n) that receives an array of integer and its length, it returns the maximum number in that array. Test your function in main. 7) Write functin reverse (char x[ .int n) that reieves an array of characters and reverse the order of its elements. Test this function in main.

  • using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings...

    using c language String Challenge Have the function StringChallenge(str) read str which will contain two strings separated by a space. The first string will consist of the following sets of characters: +, *, $, and {N} which is optional. The plus (+) character represents a single alphabetic character, the ($) character represents a number between 1-9, and the asterisk (*) represents a sequence of the same character of length 3 unless it is followed by {N} which represents how many...

  • write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy....

    write C code that uses pointers, arrays, and C strings. 3. Write a function called pow_xy. The function should be passed 2 parameters, as illustrated in the prototype below. int pow_xy(int *xptr, int y); Assuming that xptr contains the address of variable x, pow_xy should compute x to the y power, and store the result as the new value of x. The function should also return the result. Do not use the built-in C function pow. For the remaining problems,...

  • Write a function that can return the length of a string in C language. Please leave...

    Write a function that can return the length of a string in C language. Please leave comments to explain the code and verify that it runs properly... Example: Input String: China The length of the string is 5. #include <stdio.h> int length(char * p) {     /write your code here } main(){     int len;     char str[20];     printf("Input string:");     scanf("%s", str);     len = length(str);     printf("The length of string is %d. ", len);     getchar();    ...

  • Write in C language 5. [8] Write a function with prototype » void string_copy(const char source[],...

    Write in C language 5. [8] Write a function with prototype » void string_copy(const char source[], char destination[], int n); This function copies string source to string destination. Parameter n represents the size of array destination. If the latter array is not sufficiently large to hold the whole source string then only the prefix of the string which has room in the latter array should be copied. Note that after copying, the null character should also be included to mark...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT