文字列内の部分文字列を検索し、部分文字列が見つかるたびに、以下のように完全な単語を表示する必要があります-
例えば:
Input: excellent
Output: excellent,excellently
上記のような出力を作成する方法がわかりません。
私の出力:
excellent,excellently,
最後に常にコンマが表示されます。
Prog: desc 辞書内のすべての単語を繰り返し小文字に変換し、変換された単語を小文字に格納します。strncmp を使用して、input_str 以下の最初の len 文字を比較します。strncmp の戻り値が 0 の場合、2 つの文字列の最初の len 文字は同じです。
void complete(char *input_str)
{
int len = strlen(input_str);
int i, j, found;
char lower[30];
found = 0;
for(i=0;i<n_words;i++)
{
for(j=0;j<strlen(dictionary[i]);j++)
{
lower[j] = tolower(dictionary[i][j]);
}
lower[j+1]='\0';
found=strncmp(input_str,lower,len);
if(found==0)//found the string n print out
{
printf("%s",dictionary[i]);
printf(",");
}
}
if (!found) {
printf("None.\n");
} else {
printf("\n");
}
}