0
我編輯了這個問題,因爲解決方案沒有按照我的意圖工作。是否有可能編寫某種if語句或任何其他代碼,當輸入的字符串不存在於該struct數組中時,打印出錯誤消息?打印出錯誤信息後,它再次詢問字符串。我已經嘗試了一段時間,似乎無法做到正確。在結構數組中搜索字符串
int ordet=0; char_sokafras[20];
printf("Name?\n");
scanf("%s", soka_fras);
while(ordet<*num_items)
{
if(strstr(varor[ordet].name, soka_fras))
{
printf("Name found!\n");
soka[hitta_tecken]=varor[ordet];
hitta_tecken+=1;
}
ordet+=1;
}
你讀過[文件](http://man7.org/linux/man-pages/man3/strstr.3。 HTML)? – alk
這個問題還不清楚。例如,你想讓代碼提示輸入另一個字符串嗎? – user3629249