私は現在、プログラムのメイン関数(これまでのところベアボーン関数)を作成していますが、これまでは、プログラムを終了するための「end」コマンドのみを含めてきました。コマンド以外のものを入力すると、エラーメッセージが出力されます。ただし、ループ内でさらに多くのコマンドを入力しているので、他に何も認識していないようです。ユーザーに係数と指数の入力を求めた後、多項式を作成するプログラムを書いています。
コマンドはadc(係数の追加コマンド)であり、スペースの後に、係数を表す整数と、指数を表す別の整数を持つ別のスペースを追加することになっています。
例:adc 4 5出力:4x ^ 5
int main(void){
char buf[5]; //Creates string array
unsigned int choice;
printf("Command? "); // Prompts user for command
fflush(stdout);
gets(buf); //Scans the input
while(strncmp(buf, "end", 3) != 0) //Loop that goes through each case, so long as the command isn't "end".
{
switch( choice ){
//Where the other cases will inevitably go
if((strcmp(buf,"adc %d %d"))== 0){
}
break;
default:
printf("I'm sorry, but that's not a command.\n"); //Prints error message if input is not recognized command
fflush(stdout);
break;
}
printf("Command? "); //Recycles user prompt
fflush(stdout);
gets(buf);
}
puts("End of Program."); //Message displayed when program ends
}