-
Notifications
You must be signed in to change notification settings - Fork 0
/
munch1.c
62 lines (58 loc) · 1.92 KB
/
munch1.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
////////////////////////////////////////////////////////////////////////////////
// Main File: main.c
// This File: munch1.c
// Other Files: inputreader.c inputreader.h munch1.h munch2.c munch2.h
// outputwriter.c outputwriter.h Queue.c Queue.h
// Semester: CS 537 Fall 2018
//
// Author: Youmin Han
// Email: youmin.han@wisc.edu
// CS Login: youmin
//
// Author: Xianjie Zheng
// Email: xzheng97@wisc.edu
// CS Login: xianjie
//
/////////////////////////// OTHER SOURCES OF HELP //////////////////////////////
// fully acknowledge and credit all sources of help,
// other than Instructors and TAs.
//
// Persons: NULL
//
// Online sources: NULL
//
//////////////////////////// 80 columns wide ///////////////////////////////////
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <pthread.h>
#include "Queue.h"
#include "munch1.h"
#define buffersize 1024
#define qsize 10
/*
* Scan the line and replace each space character (not tabs or newlines) with
* an asterisk ("*") character. It will then pass the line to thread Munch2
* through another queue of character strings.
* @param: array
* struct that store three different queues
*/
void *munch1(void *array) {
// get queues from queuelist
Queue *qreader = ((queuelist*)array)->qreader;
Queue *qmunch1 = ((queuelist*)array)->qmunch1;
char *str;
// traverse all strings in the reader queue
while((str = DequeueString(qreader)) != NULL) {
// change every space character to star
while(index(str, ' ') != NULL) {
*index(str, ' ') = '*';
}
// add changed strings to next queue
EnqueueString(qmunch1, str);
}
// add NULL to queue as a sign of there will be no more input
EnqueueString(qmunch1, NULL);
pthread_exit(NULL);
}