Beginner programmer here, trying to figure out how to find and print the longest common prefix in C.
I have a base here for the program.
#include <stdio.h>
void findprefix(char *str1, char *str2, char *found);
int main(void) {
char str1[100];
char str2[100];
char found[10] = { '\0' };
printf("\nGive string 1: ");
scanf("%99s", str1);
printf("\nGive string 2: ");
scanf("%99s", str2);
//Print prefix
findprefix(str1, str2, found);
printf("%s", found);
return 0;
}
//Function to find the longest common prefix
void findprefix(char *str1, char *str2, char *found) {
int i, j;
for () {
if () {
}
}
}
The initial idea is to use a for loop and an if statement in the function but I'm not sure how.