summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c23
1 files changed, 11 insertions, 12 deletions
diff --git a/main.c b/main.c
index 650d646..e8decd9 100644
--- a/main.c
+++ b/main.c
@@ -10,6 +10,7 @@
struct com_struct {
char *com;
char *arg;
+ int error; // 0: okay 1: not okay
};
void test() {
@@ -36,7 +37,8 @@ void ls(const char *path) {
// print the folder|directory name
while ((entry = readdir(dP)) != NULL) {
- printf("%s", entry->d_name);
+ char *temporary_variable = entry->d_name;
+ printf("%s\n", entry->d_name);
}
closedir(dP);
}
@@ -44,14 +46,13 @@ void ls(const char *path) {
struct com_struct split_command(char *input) {
struct com_struct NEW_COMMAND;
- const char *command = strtok(input, " ");
- const char *argument = strtok(NULL, " ");
+ char *command = strtok(input, " ");
+ char *argument = strtok(NULL, " ");
if (command != NULL) {
NEW_COMMAND.com = strdup(command);
- } else
- {
+ } else {
printf("failed, null pointer detected");
free(command);
}
@@ -62,6 +63,7 @@ struct com_struct split_command(char *input) {
printf("failed, null pointer detected");
free(argument);
}
+ NEW_COMMAND.error = 1;
return NEW_COMMAND;
}
@@ -72,7 +74,7 @@ int main(void) {
printf("\n$ ");
fgets(input, MAX_COMMAND_LENGTH, stdin);
- const struct com_struct new_input = split_command(input);
+ struct com_struct new_input = split_command(input);
new_input.com[strcspn(new_input.com, "\n")] = '\0';
@@ -86,12 +88,9 @@ int main(void) {
}
if (strcmp(new_input.com, "ls\n") == 0) {
printf("DETECTED LS COMMAND");
- if (new_input.arg == NULL) {
- printf("\nARGUMENT NOT DEFINED");
- free(new_input.com);
- free(new_input.arg);
- continue;
- }
+ printf("\nARGUMENT NOT DEFINED");
+ free(new_input.com);
+ free(new_input.arg);
ls(new_input.arg);
}
if (strcmp(new_input.com, "echo\n") == 0) {