-
Notifications
You must be signed in to change notification settings - Fork 0
/
universalFunctions.c
73 lines (63 loc) · 1.27 KB
/
universalFunctions.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
//
// universalFunctions.c
//
//
// Created by Chris Gross on 12/8/11.
// Copyright 2011 Case Western Reserve University All rights reserved.
//
void error(const char *msg) //prints errors
{
perror(msg);
exit(1);
}
int exitCall(char *str) //checks for exit
{
if(!strcmp(str, EXIT_CALL) || ! strcmp(str, TIMEOUT_CALL))
{
return 0;
}
else
{
return 1;
}
}
int chop(char *str) //chops off the new line
{
int len = strlen(str);
if( str[len-1] == '\n' )
{
str[len-1] = 0;
}
else if(len == 0)
{
return 0;
}
return 1;
}
void zeroBuffer(char *buffer)
{
memset(buffer, 0, MAX_MESSAGE_SIZE); //zero out the buffer
}
void addCommand(char *buffer, int command)
{
memmove(buffer, (buffer - 2), MAX_MESSAGE_SIZE);
buffer[COMMAND_LOCATION] = command;
}
void clearScreen()
{
if (system("cls"))
system("clear");
}
void grabContents(char *buffer) //grabs contents of the buffer ie the message minus the command
{
int x = 0;
char character = buffer[COMMAND_LOCATION + 1];
while (character != '\0')
{
character = buffer [x + COMMAND_LOCATION + 1];
buffer[x] = character;
x++;
}
buffer[x] = 0;
buffer[x - 1] = 0;
}