Home > Enterprise >  Clion IDE comments my second part of code. What can I do?
Clion IDE comments my second part of code. What can I do?

Time:02-24

Hi I am writing some code for finite automata but that is not important.

When I try to write in CLion my second part of the code is commented (from line 32 case JEDNORADKOVA). Do you know how can I repair my CLion or where is problem then?

My code:

#include <stdio.h>


typedef enum {START ,POSSIBLE_COMMENT, SINGLE_LINECOMMENT, MULTILINECOMMENT,MULTILINECOMMENT_MAYBE_END, QUOTATION_MARKS} tStates;

int main() {
  tStates state = START;
    printf("Delete of comments. Enter input \n");
    int sighn ;

    while((sighn=getchar())  != EOF)
    {
        switch (state) {
            case START:
                if (sighn == '/') {
                  state = POSSIBLE_COMMENT; }
                else{
                    putchar(sighn);
                }



            case SINGLE_LINECOMMENT:
                if (sighn == '\n')
                    state=  START;

                case MULTILINECOMMENT:
                 if (sighn == '*')

                break;



            case MULTILINECOMMENT_MAYBE_END:


            case QUOTATION_MARKS:


                break;
        }
    }
    return 0;
}

MY code in CLion

MY code in CLion

My code in VS Code

My code in VS Code

CodePudding user response:

Read the messages in CLion: "Unreachable code :32" and the error is clear.

I have formatted your source, but it seems to be not the one you have in CLion. Since the indenting and bracing are chaotic, I assume that you have a closing brace too much.

CodePudding user response:

regarding:

case MOZNA_POZNAMKA:
            if (znak == '/')
                stav = JEDNORADKOVA;
            else
                putchar('/');
                
            putchar(znak);
            stav = START;
            break;

regardless of the value in znak, this will print one or two '/' characters then set the next 'switch' selector to START probably not what you want as it results in the next couple of cases never being executed

  • Related