Consider I'm still a newbie with C, so I made a lot of confusion. This code works fine
int error(int a, int b, int c)
{
if (( a < 0 ) || (a > 255)) {
printf("Number is over 255 or under 0, exit \n");
exit(1); }
if ((a < 0)|| (a > 255)) {
printf("Number is over 255 or under 0, exit \n");
exit(1);
}
else if ((b < 0)|| (b > 255)) {
printf("Number is over 255 or under 0, exit \n");
exit(1);
}
else if ((c < 0)|| (c > 255)) {
printf("Number is over 255 or under 0, exit \n");
exit(1);
}
else {
true;
}
}
But is too long and I don't like it, I want to create an array which take the values of a b and c, and compare it with 255 or 0 (separately: for example a=256 failed, b=23 ok, c=33 ok), and if is over 255 or under 0, exit. I have tried this code but I have failed
int array[] = {a, b, c};
if( array[a] >= MAX_SIZE){
printf("Number is over 255 or under 0, exit \n");
exit(1);
}
true;doesn't really do anything. And if you declare a function to return a non-void value, then you must have an explicitreturnstatement.