-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost.c
64 lines (64 loc) · 2.29 KB
/
post.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
/*Domenic Bianchi*/
/*CIS 2750 Assignment 2*/
/*February 19 , 2017*/
/*This program gets user input to create a new post*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#include "stream.h"
#include "addauthor.h"
struct postEntry {
void(*postEntrysubmitPost)();
void(*postEntrygetTimeAndDatec)(char*);
userPost*(*postEntryformatEntrycccc)(char*,char*,char*,char*);
};
userPost * postEntryformatEntrycccc ( char name[] , char stream[] , char text[] , char dateAndTime[] ) {
userPost * current ;
/*Malloc memory for the Post node*/
current = malloc ( sizeof ( userPost ) ) ;
/*If the malloc fails , do not create the node*/
if ( current == NULL ) {
free ( current ) ;
return NULL ;
}
current->username = name ;
current->streamname = stream ;
current->date = dateAndTime ;
current->text = text ;
return current ;
}
void postEntrygetTimeAndDatec ( char string[] ) {
time_t currentTime ;
struct tm * timeStruct ;
/*Get the current data and time from the machine this program is being run on*/
currentTime = time ( NULL ) ;
timeStruct = localtime ( ¤tTime ) ;
/*Format the time string in order to be parsed correctly in the python script*/
strftime ( string , 256 , "%b. %d, %Y %H:%M:%S\n" , timeStruct ) ;
}
void postEntrysubmitPost ( userPost * post ) {
/*updateStream is a library function*/
updateStream ( post ) ;
free ( post ) ;
}
void constructorpostEntry (struct postEntry * ptr) {
ptr->postEntrysubmitPost = postEntrysubmitPost;
ptr->postEntrygetTimeAndDatec = postEntrygetTimeAndDatec;
ptr->postEntryformatEntrycccc = postEntryformatEntrycccc;
}
int main ( int argc , char * argv[] ) {
struct postEntry post ;
constructorpostEntry(&post);
userPost * fullPost ;
char dateAndTime[256] ;
clearArray ( dateAndTime , 256 ) ;
/*Get the time and date*/
post.postEntrygetTimeAndDatec ( dateAndTime ) ;
/*Format all the inputed information into a struct that can be sent to the stream library*/
fullPost = post.postEntryformatEntrycccc ( argv[1] , argv[2] , argv[3] , dateAndTime ) ;
/*Send struct to stream library*/
post.postEntrysubmitPost ( fullPost ) ;
return 0 ;
}