Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #define BUFSIZE 10000
- int space;
- char** createArray(char *line) {
- int len_line = strlen(line);
- char **wordArray = NULL;
- if(len_line > 1){
- char *token = strtok(line, " ");
- space = 0;
- while (token) {
- wordArray = realloc(wordArray, sizeof(char*)*++space);
- wordArray[space-1] = token;
- token = strtok(NULL, " ");
- }
- }
- return wordArray;
- }
- int main(int argc, const char* argv[]) {
- char line[BUFSIZE];
- while (1) {
- printf("%sn", ">");
- fgets(line, BUFSIZE, stdin);
- char** l = createArray(line);
- if (l) {
- /*why instaed of zero, when l[0]
- /*equals quit, strcmp() returns 10?*/
- printf("%dn", strcmp(l[0], "exit"));
- if(strcmp(l[0], "exit")==10) {
- exit(0);
- }
- else if(fork() == 0) {
- execv(l[0], l);
- printf("%sn", "Error!");
- }
- }
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement