-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lab2MainEdit.c
41 lines (33 loc) · 1.06 KB
/
Lab2MainEdit.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
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINE_LENGTH 80
#define LIN_COUNT 20
int main(int argc, char* argv[])
{
char line[LINE_LENGTH];
while (strcmp(line, "quit") != 0 || strcmp(line, "quit ") != 0
|| strcmp(line, "quit\t") != 0 || strcmp(line, " quit") != 0 || strcmp(line, "\tquit") != 0)
{
printf("prompt>");
printf("%");
fgets(line, LINE_LENGTH, stdin);
if(sizeof(line) > LINE_LENGTH)
{
printf("Cannot enter a command more than 80 chars");
}
//Removes \n
if ((strlen(line)>0) && (line[strlen(line) - 1] == '\n'))
line[strlen(line) - 1] = '\0';
//Execute command
//execve(line, char *const argv[],char *const envp[]);
//Exit command
if (strstr(line, "quit") != NULL || strstr(line, "quit ") != NULL || strstr(line, "quit\t") != NULL ||
strstr(line, " quit") != NULL || strstr(line, "\tquit") != NULL)
{
exit(0);
}
}
return 0;
}