Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何将输入字符串数组设置为仅接受来自 STDIN 的特定字母?
char arr[testcases][100]; for(i=0;i<testcases;i++){ scanf("%99s",&arr[i]); }
我将只在我的数组中存储字母a、b、c、d 。如何限制其他字母存储在我的数组中?
你可以使用这个:
scanf("%99[a-d]", arr);
1如果字符串的任何初始部分匹配,则返回值;输入将在第一个不匹配的字符处停止。
1