why am i getting error in this switch statement written in c

Posted by mekasperasky on Stack Overflow See other posts from Stack Overflow or by mekasperasky
Published on 2010-04-18T23:07:31Z Indexed on 2010/04/18 23:13 UTC
Read the original article Hit count: 650

Filed under:

I have a character array b which stores different identifiers in different iterations . I have to compare b with various identifiers of the programming language C and print it into a file . When i do it using the following switch statement it gives me errors

b[i]='\0';
        switch(b[i])
        {
            case "if":fprintf(fp2,"if ---->  IDENTIFIER \n");
            case "then":fprintf(fp2,"then ---->  IDENTIFIER \n");
                case "else":fprintf(fp2,"else ----> IDENTIFIER  \n");
                case "switch":fprintf(fp2,"switch ----> IDENTIFIER  \n");
                case 'printf':fprintf(fp2,"prtintf ----> IDENTIFIER  \n");
                case 'scanf':fprintf(fp2,"else ----> IDENTIFIER  \n");
                case 'NULL':fprintf(fp2,"NULL ----> IDENTIFIER  \n");
                case 'int':fprintf(fp2,"INT ----> IDENTIFIER  \n");
                case 'char':fprintf(fp2,"char ----> IDENTIFIER  \n");
                case 'float':fprintf(fp2,"float ----> IDENTIFIER  \n");
                case 'long':fprintf(fp2,"long ----> IDENTIFIER \n");
                case 'double':fprintf(fp2,"double ----> IDENTIFIER \n");
                case 'char':fprintf(fp2,"char ----> IDENTIFIER \n");
                case 'const':fprintf(fp2,"const ----> IDENTIFIER \n");
                case 'continue':fprintf(fp2,"continue ----> IDENTIFIER \n");
                case 'break':fprintf(fp2,"long ----> IDENTIFIER \n");
                case 'for':fprintf(fp2,"long ----> IDENTIFIER \n");
                case 'size of':fprintf(fp2,"size of ----> IDENTIFIER \n");
                case 'register':fprintf(fp2,"register ----> IDENTIFIER \n");
                case 'short':fprintf(fp2,"short ----> IDENTIFIER \n");
            case 'auto':fprintf(fp2,"auto ----> IDENTIFIER \n");
                case 'while':fprintf(fp2,"while ----> IDENTIFIER \n");
                case 'do':fprintf(fp2,"do ----> IDENTIFIER \n");
                case 'case':fprintf(fp2,"case ----> IDENTIFIER \n");

            }

the error being

lex.c:94:13: warning: character constant too long for its type
lex.c:95:13: warning: character constant too long for its type
lex.c:96:13: warning: multi-character character constant
lex.c:97:13: warning: multi-character character constant
lex.c:98:13: warning: multi-character character constant
lex.c:99:13: warning: character constant too long for its type
lex.c:100:13: warning: multi-character character constant
lex.c:101:13: warning: character constant too long for its type
lex.c:102:13: warning: multi-character character constant
lex.c:103:13: warning: character constant too long for its type
lex.c:104:13: warning: character constant too long for its type
lex.c:105:13: warning: character constant too long for its type
lex.c:106:13: warning: multi-character character constant
lex.c:107:13: warning: character constant too long for its type
lex.c:108:13: warning: character constant too long for its type
lex.c:109:13: warning: character constant too long for its type
lex.c:110:12: warning: multi-character character constant
lex.c:111:13: warning: character constant too long for its type
lex.c:112:13: warning: multi-character character constant
lex.c:113:13: warning: multi-character character constant
lex.c: In function ‘int main()’:
lex.c:90: error: case label does not reduce to an integer constant
lex.c:91: error: case label does not reduce to an integer constant
lex.c:92: error: case label does not reduce to an integer constant
lex.c:93: error: case label does not reduce to an integer constant
lex.c:94: warning: overflow in implicit constant conversion
lex.c:95: warning: overflow in implicit constant conversion
lex.c:95: error: duplicate case value
lex.c:94: error: previously used here
lex.c:96: warning: overflow in implicit constant conversion
lex.c:97: warning: overflow in implicit constant conversion
lex.c:98: warning: overflow in implicit constant conversion
lex.c:99: warning: overflow in implicit constant conversion
lex.c:99: error: duplicate case value
lex.c:97: error: previously used here
lex.c:100: warning: overflow in implicit constant conversion
lex.c:101: warning: overflow in implicit constant conversion
lex.c:102: warning: overflow in implicit constant conversion
lex.c:102: error: duplicate case value
lex.c:98: error: previously used here
lex.c:103: warning: overflow in implicit constant conversion
lex.c:103: error: duplicate case value
lex.c:97: error: previously used here
lex.c:104: warning: overflow in implicit constant conversion
lex.c:104: error: duplicate case value
lex.c:101: error: previously used here
lex.c:105: warning: overflow in implicit constant conversion
lex.c:106: warning: overflow in implicit constant conversion
lex.c:106: error: duplicate case value
lex.c:98: error: previously used here
lex.c:107: warning: overflow in implicit constant conversion
lex.c:107: error: duplicate case value
lex.c:94: error: previously used here
lex.c:108: warning: overflow in implicit constant conversion
lex.c:108: error: duplicate case value
lex.c:98: error: previously used here
lex.c:109: warning: overflow in implicit constant conversion
lex.c:109: error: duplicate case value
lex.c:97: error: previously used here
lex.c:110: warning: overflow in implicit constant conversion

lex.c:111: warning: overflow in implicit constant conversion lex.c:111: error: duplicate case value lex.c:101: error: previously used here lex.c:112: warning: overflow in implicit constant conversion lex.c:112: error: duplicate case value lex.c:110: error: previously used here lex.c:113: warning: overflow in implicit constant conversion lex.c:113: error: duplicate case value lex.c:101: error: previously used here

© Stack Overflow or respective owner

Related posts about c