-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMLFQ.c
65 lines (59 loc) · 1.08 KB
/
MLFQ.c
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
char filelist[100][400];
int N = 0;
void strtolower(char arr[])
{
for(int i = 0; i < strlen(arr); i++)
{
if(isupper(arr[i]) && isalpha(arr[i]))
arr[i] = tolower((unsigned char)arr[i]); // Typecast to (unsigned char)?
}
}
void *grep(void *s)
{
char *temp = (char *)s;
char search[100];
strcpy(search, temp);
char temp2[300];
strtolower(search);
for(int i = 0; i < N; i++)
{
strcpy(temp2, filelist[i]);
strtolower(temp2);
char *res = strstr(temp2, search);
if(res != NULL)
{
printf("%s\n", filelist[i]);
}
}
pthread_exit(NULL);
}
int main(void)
{
int T, rc;
pthread_t thread;
scanf("%d", &N);
getchar();
for(int i = 0; i < N; i++)
{
scanf("%[^\n]s", filelist[i]);
getchar();
}
scanf("%d", &T);
getchar();
for(int i = 0; i < T; i++)
{
char search[200];
scanf("%[^\n]s", search);
getchar();
rc = pthread_create(&thread, NULL, grep, (void *)search);
if(rc)
printf("Error in grep thread creation : %d\n", rc);
pthread_join(thread, NULL);
}
return 0;
}