【发布时间】:2013-11-16 04:29:35
【问题描述】:
每次找到子字符串时,我都必须在字符串中搜索子字符串并显示下面给出的完整单词-
例如:
Input: excellent
Output: excellent,excellently
我不知道如何制作像上面那样的输出。
我的输出:
excellent,excellently,
最后总是给我一个逗号。
程序:描述 迭代地将字典中的每个单词转换为小写, 并将转换后的单词存储在较低的位置。 使用 strncmp 比较 input_str 的前 len 个字符和更低的字符。 如果strncmp的返回值为0,那么前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");
}
}
【问题讨论】: