forked from msteinbiss/Shell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshell.c
More file actions
41 lines (31 loc) · 656 Bytes
/
shell.c
File metadata and controls
41 lines (31 loc) · 656 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char **argv){
//char **args;
size_t length = 0;
while(1){
char *line;
printf("$ ");
//read the line
getline(&line, &length, stdin);
//parse it
int len_of_cmd = strlen(line);
char **arr = (char **) malloc(len_of_cmd * sizeof(char *));
int i = 0;
char *token;
char delim[] = " ";
token = strtok(line, delim);
while(token != NULL){
arr[i] = (char *)malloc(strlen(token) + 1);
arr[i] = token;
i++;
token = strtok(NULL, delim);
}
int j;
for (j=0;j<i;j++){
printf("token %i: %s\n", j, arr[j]);
}
}
//free the space
}