简体   繁体   中英

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(a != b[]){
    printf("Use another value!");
}

Where b[] is any value within the array. 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!"

I thought I should specify that I am doing this is C

in C# you can go

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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