私の出力では、正しいためにNULL文字が必要であることを除いて、すべて問題ありません。何が間違っているのかというと、forループの後に配列との間の条件をチェックする*ans[]={"zero","one","two"};
ことです。これは、NULL 入力が受け入れられる原因となる私の制限です。forループで制限を超えないようにするにはどうすればよいですか?inp
sel
2
sel++
sel = 3
sel
#include <stdio.h>
#include <conio.h>
#include <string.h>
void main(){
char inp[256]={0},
*ans[]={"zero","one","two"};
int sel,
ans_cnt=sizeof(ans)/sizeof(ans[0]); // Equals to 3
do{
clrscr();
printf("Enter Any:\n\"zero\" or \n\"one\" or \n\"three\": ");
gets(inp);
for(sel=0;sel<ans_cnt && strcmp(inp,ans[sel]);sel++);
}
while(strcmp(inp,ans[sel]));
printf("Valid Answer!");
getch();
}