Fix commandCallHanler

master
germanFid 2022-06-17 12:39:35 +03:00
parent 47948489ed
commit 250c2b868b
2 changed files with 25 additions and 4 deletions

View File

@ -9,10 +9,16 @@
#define MAX_COMMAND_LEN 200
void clearExtraInput()
{
int c;
while ((c = getchar()) != '\n' && c != EOF) {}
}
int getString(char* str, const int size)
{
char* buf = (char*) malloc(size + 1);
if (gets(buf) == NULL)
if (fgets(buf, size, stdin) == NULL)
{
return GETSTRING_ERR_RE;
}
@ -28,7 +34,7 @@ int getString(char* str, const int size)
return 0;
}
int commandCallHandler()
char* commandCallHandler()
{
char* command = (char*) malloc(MAX_COMMAND_LEN);
char* buf = (char*) malloc(MAX_COMMAND_LEN);
@ -37,11 +43,12 @@ int commandCallHandler()
result = getString(command, MAX_COMMAND_LEN-1);
if (result == 0)
{
// Разбиваем на лексемы и обрабатываем команду
strcpy(buf, command);
return buf;
}
else
{
return -1;
return NULL;
}
}

14
main.c
View File

@ -5,5 +5,19 @@
int main(int argc, char** argv)
{
char* buf;
while (1)
{
buf = commandCallHandler();
if (buf == 0)
{
printf("Unknown Command!");
}
}
return 0;
}