我正在创建一个非常基本的外壳。当用户在不键入任何命令的情况下按下Enter键时,程序应转到下一行并继续。如果用户键入任何命令,程序应打印一条文本消息。我在使用空字符串条件时遇到问题。
尝试使用另一个char数组的strcmp。
#include <stdio.h>
#include <string.h>
int main()
{
char input[256];
char str[4] = {"exit"};
do
{
printf("CSC327> ");
scanf("%[^\n]", &input);
if(getchar() == '\n')
continue;
if(strcmpi(input, str))
printf("Command not found!\n");
}
while(strcmpi(input,str));
printf("\nGoodbye.");
}//main ends