Hello everyone,
I was working on a program which accepts 2 strings from the keyboard and the compared n characters from both strings. If n characters from each string equals then print out message saying that else print message saying otherwise. I know that I can use strncmp() function here, and also I need a loop to make a decision. It sounds simple but for some reason I cant make it work. Here is my code:
Please help me with this codeCode:#include <stdio.h> #include <string.h> int main() { char string1[20], string2[20]; int n, result = 0; printf("\nEnter String 1:"); gets(string1); printf("\nEnter String 2:"); gets(string2); printf("\nEnter the n:"); scanf("%d", &n); int result = strncmp(string1,string2,n); // strncmp() function if (result > 0) // I am not sure what I am doing there printf("\nMatch"); else printf("\nNot a Match");
Thank you