[英]search and compare a string with an array of strings
这是我的代码
const char *s[5];={"abcd","efgh","ijkl","mnop","qrst"};
char a[4];
while (1)
{
scanf("%4s",&a);
//compare a with s array
if(/*a exists in s*/)
printf("it is ok");
if(/*a does not exist in s*/)
printf("it is not ok");
}
例如,当我键入“ dcba”时,我想看到“它不正常”。 当我输入“ efgh”时,我想看到“没问题”。
如果您使用的是C ++和std::string
类,则可以使用std::vector<string>
和<algorithm>
的std::find
查找字符串。
由于您使用的是C样式的字符串,请在参考书中搜索strcmp
以比较容器中的某项与C样式的字符串变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.