I am trying to make a shell program and am working on mkdir, I am reading in the user input and breaking it into segments using sscanf and then trying to use strcmp to check if the first word was "mkdir", the strcmp works if I leave the stdin as is without using sscanf. Can someone tell me why it doesn't work like this, and how to fix it? Thanks,
//#include "parser.c"
#include <stdio.h>
# include <sys/stat.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#ifndef MAX_BUF
#define MAX_BUF 200
#endif
int main(void)
{
while (1) {
printf("Enter a command: ");
char input[20];
char line[4][20];
fgets(input, 20, stdin);
sscanf(input, "%s %s", line[0], line[1]);
if(strcmp(line[0], "mkdir")) {
char path[MAX_BUF];
getcwd(path, MAX_BUF);
strcat(path, "/");
strcat(path, line[1]);
mkdir(path, 0700);
printf(path);
}
//printf("output %s", input);
}
}