-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream.c
76 lines (55 loc) · 1.63 KB
/
stream.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
66
67
68
69
70
71
72
73
74
75
76
/*Domenic Bianchi
CIS 2750 Assignment 2
February 19, 2017
This program creates files neccessary to create a stream, add a user to a user file, or remove a user from a user file. Also, this program adds posts to the appropriate stream*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "stream.h"
#include "addauthor.h"
void updateStream(userPost * st) {
char command[7500];
clearArray(command, 7500);
strcat(command, "./db -addPost \"");
strcat(command, st->streamname);
strcat(command, "\" \"");
strcat(command, st->username);
strcat(command, "\" \"");
strcat(command, st->date);
strcat(command, "\" \"");
strcat(command, st->text);
strcat(command, "\"");
system(command);
}
void addUser(char * username, char * list, char * statusMessage) {
char * streamToAdd;
/*Tokenize all streams that the user is being added to*/
streamToAdd = strtok(list,",");
while (streamToAdd != NULL) {
char command[7500];
clearArray(command, 7500);
strcat(command, "./db -addAuthor \"");
strcat(command, streamToAdd);
strcat(command, "\" \"");
strcat(command, username);
strcat(command, "\"");
system(command);
streamToAdd = strtok(NULL, " ,");
}
}
void removeUser(char * username, char * list) {
char * streamToRemove;
streamToRemove = strtok(list,",");
/*Loop through each stream the user entered*/
while (streamToRemove != NULL) {
char command[7500];
clearArray(command, 7500);
strcat(command, "./db -removeAuthor \"");
strcat(command, streamToRemove);
strcat(command, "\" \"");
strcat(command, username);
strcat(command, "\"");
system(command);
streamToRemove = strtok(NULL, " ,");
}
}