我目前正在用 C 语言制作一个字典程序。如何检测 stdin 上的空字符串?使用 search_for 作为我的输入。
void find_track(char search_for[])
{
int i;
for (i = 0; i < 5; i++) {
if (strstr(tracks[i], search_for)){
printf("The meaning of %s: %s\n",tracks[i], meaning[i]);
break;
}
}
if (!strstr(tracks[i], search_for)) {
printf("%s could not found in dictionary.\n",search_for);
}
}
同样,如何使用 tolower 函数降低输入?
int main()
{
int setloop =1;
titlemessage();
do {
char search_for[80];
char varchar;
printf("Search for: ");
fgets(search_for, 80, stdin);
if(search_for[strlen(search_for)-1]=='\n')
search_for[strlen(search_for)-1]='\0';
find_track(search_for);
printf("Press ENTER to start new search\n");
//printf("Press 'q' to exit the program\n\n");
varchar = getchar();
if (varchar == 10) {
continue;
}else {
break;
}
} while (setloop = 1);
return 0;
}
任何方法将不胜感激。