Complete a function definition in C for strmatch. For this problem, you can't use any <string.h> library functions.
In c, two strings match exactly if they have the same characters in the same order and same length. Consider this:
int strmatch(const char *x, const char *b);
//Needs each of x and y points to the beginning of a string.
//Promises to return value 1 if the two strings match exactly. If they don't match, the return value is 0.
For instance: the value of strmatch("xyz", "xyz") should be 1;
the value of strmatch("xy", "xyz") should be 0;
#include <stdio.h> int strmatch(const char *x, const char *b){ int i = 0; while(!(x[i]=='\0' || b[i]=='\0')){ if(x[i]!=b[i]){ return 0; } i++; } if(x[i]=='\0' && b[i]=='\0'){ return 1; } return 0; } int main() { printf("%d\n",strmatch("xyz", "xyz")); printf("%d\n",strmatch("xy", "xyz")); return 0; }
Get Answers For Free
Most questions answered within 1 hours.