我正在获取一个字符串数字列表,并将它们与数组中字符串数字列表进行比较。当列表中的数字与数组中的数字匹配时,将显示“找到匹配项”。对于匹配的号码,不应显示任何其他内容。对于数字 6,显示“未找到匹配项”。
列表: 12346
数组: 12345
注意:
while(not end of file)
{
for(i = 0; i < arraycount; i++)
{
if(strcmp(numberlist.numbers,array[i].numbers) == 0)
//Display "Match Found"
}
}
我不确定在这一点之后该做什么,或者我是否正在接近这个权利。如果我在 if 语句之后放置一个显示“未找到”的 else 语句,那么它会显示为“找到匹配”数字。
我不想要的示例:
1 Match Found Not Found Not Found Not Found Not Found
2 Not Found Match Found Not Found Not Found Not Found
3 Not Found Not Found Match Found Not Found Not Found
4 Not Found Not Found Not Found Match Found Not Found
6 Not Found Not Found Not Found Not Found Not Found
我想要的例子:
1 Match Found
2 Match Found
3 Match Found
4 Match Found
6 Not Found
这是针对初学者的类(class),因此我必须将代码保持在初学者水平。
编辑:
解决方案
while(not end of file)
{
for(i = 0; i < arraycount; i++)
{
found = 0;
if(strcmp(numberlist.numbers,array[i].numbers) == 0)
found = 1;
//Display "Match Found"
}
if (found != 1)
//Display "Not Found"
}
最佳答案
解决方案
while(not end of file)
{
for(i = 0; i < arraycount; i++)
{
found = 0;
if(strcmp(numberlist.numbers,array[i].numbers) == 0)
found = 1;
//Display "Match Found"
}
if (found != 1)
//Display "Not Found"
}
关于C - 将数字列表与数组进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28778849/