简体   繁体   English

设置限制在数组中的值的东西?

[英]Setting up something that is limited to a value within an array?

I am currently working on a project and I'm not entirely sure how to do this but I want to have an if statement that has something along the lines of this 我目前正在研究一个项目,但我不完全确定该怎么做,但我想拥有一条if语句,其中包含与此类似的内容

if(a != b[]){
    printf("Use another value!");
}

Where b[] is any value within the array. 其中b []是数组中的任何值。 So for example if I have 100 values and what the user inputted was not any of those then it would then print "Use another value!" 因此,例如,如果我有100个值,而用户输入的值不是其中的任何一个,则它将打印“使用另一个值!”。

I thought I should specify that I am doing this is C 我想我应该指定我正在执行的操作是C

in C# you can go 在C#中,您可以

ArrayVariable.Contains(object) ArrayVariable.Contains(object)

you can iterate thorugh the loop and check it's value 您可以遍历循环并检查其值

for(int i=0;i<sizeof(b);i++)
{
   if(a!=b[i]
   {
    printf("Use another value");
    break;
  }
}

i guess its done in this way.I have not really used C in a long time. 我想它是用这种方式完成的。我已经很长时间没有真正使用过C了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM