Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Label does not reduce to an integer constant

error running this c program . i'm getting an error like" case label doesnot reduce to an integer constant ". help me in finding my errors . i'm a newbie to c, started it a few weeks ago.thanks in advance

 #include<stdio.h>
 main()  
  { int a,b,c;
  scanf("%d",&c);
   if (c<5) {
    c==a  ;
   }
   else { c==b;
   }
    switch (c)
   {
    case a:
       printf ("statement1");
       break;
    case b :
       printf(" statement2");
     break;
    }
    }

1 Answers

In C, which you seem to be calling c# for some reason, case labels must be integer constants.

6.8.4.2-3

The expression of each case label shall be an integer constant expression and no two of the case constant expressions in the same switch statement shall have the same value after conversion.

Not sure if this is what you want, but you could try:

switch (c) {
case 'a':
    break;
case 'b':
    break;
}

Otherwise, maybe you want

if (c == a)
    /* ... */
else if (c == b)
    /* ... */
else
    /* ... */

As side note, you probably want c=a instead of c==a.

like image 192
cnicutar Avatar answered Mar 24 '26 04:03

cnicutar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!