-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatch.c
More file actions
39 lines (36 loc) · 1.17 KB
/
Copy pathmatch.c
File metadata and controls
39 lines (36 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
int match(char *s, char *t);
int main()
{
char pattern[sysconf(_SC_BC_STRING_MAX)], text[sysconf(_SC_BC_STRING_MAX)];
int low, endLoop, current, t_size, p_size;
endLoop = current = 0;
printf("please enter a pattern and text to comapre: ");
scanf("%s", pattern);
low = p_size = strlen(pattern);
for(;;) {
printf("please enter a text to match, enter 1 when done: ");
scanf("%s", text);
t_size = strlen(text);
if ((endLoop = atoi(text)) == 1)
break;
if (p_size >= t_size)
current = mystrcmp(pattern, text);
else
current = mystrcmp(text, pattern);
low = (current < low) ? current : low;
}
printf("the lowest number of unmatched characters is: %d\n", low);
return 0;
}
int match(char *s, char *t)
{
int i, unmatched=0;
for (i=0; s[i] != '\0'; i++)
if(s[i] != t[i])
unmatched++;
return unmatched;
}