Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does this SWITCH error mean?

I'm getting this error for my CASE 5/6/7/8.

I'm sure it's something obvious as it was working before I started adding addition function calls to CASE 4.

What does the error mean?

error: case label in scope of identifier with variably modified type not containing enclosing switch statement

 switch(menu_selection())
    {
        case 0 :    i = find_empty_record(data_record);       //New record
                    if (i!=-99)
                    {
                        printf("\n\nRecord #%d found to be empty...\n\n",i);
                        data_entry(&data_record[i],i,&array_flag);
                    }
        break;

        case 1  :                                             //Edit
                i=record_selection(array_flag);
                data_entry(&data_record[i],i,&array_flag);
        break;

        case 2  :   display_single(data_record,array_flag);  //Display single record

        break;

        case 3  :                                           //Display all records
                for (i=0;i<30;i++)
                    {
                        print_2_screen(&data_record[i],i,array_flag);
                    }
        break;

        case 4  :   rec_cnt = get_text_file_size(import_file_name); //Import Text File
                    student_record data_record[rec_cnt];
                    import_text_file(data_record,import_file_name,array_flag,rec_cnt);
        break;


        case 5  :   //  Import Binary File
        break;


        case 6  :
                export_text(data_record,rec_cnt,array_flag);//  Save to Text File
        break;

        case 7  :   //  Save to Binary File
        break;

        default :
        break;
    }

}
return 0;
like image 499
Chef Flambe Avatar asked Mar 11 '12 09:03

Chef Flambe


2 Answers

student_record data_record[rec_cnt];

You can't declare stuff inside a switch.

  • Do it before the switch
  • Do it in a block:

    case 4:
    {
        student_record data_record[rec_cnt];
        /* ... */
    }
    
like image 181
cnicutar Avatar answered Nov 17 '22 07:11

cnicutar


In case 4 you have an array declaration: student_record data_record[rec_cnt];

Create an extra block:

case 4:   
  {
    rec_cnt = get_text_file_size(import_file_name); //Import Text File
    student_record data_record[rec_cnt];
    import_text_file(data_record,import_file_name,array_flag,rec_cnt);
  }
  break;
like image 25
Karoly Horvath Avatar answered Nov 17 '22 07:11

Karoly Horvath