2010-04-24 3 views
5

Non conosco la causa di questi errori che sto ricevendo da Visual Studio 2010.Qual è la causa di questi errori e avvisi di Visual Studio 2010?

Questo è il codice del mio programma dalla linea 343 alla linea 408:

int create_den_from_img(char *img_file_name_part, int xlen, int ylen, int zlen) 
{ 
    IplImage* imgs = 0; 
    char str[80]; 
    unsigned char *data,*imgdata; 

    /* allocating memory */ 
    data = (unsigned char *) malloc(xlen * ylen * zlen * sizeof(unsigned char)); 
    if(data==NULL) 
    { 
    printf("error in allocating memory \n"); 
    exit(1); 
    } 

    /* Getting the filename & iterating through tiff images */ 

    for(int k = 0; k < zlen; k++) 
    { 
     int count=2; 
     int tmp=k+1; 
     while(tmp/10) 
     { 
      count=count-1; 
      tmp=tmp/10; 
     } 

     switch(count) 
     { 
      case 2:sprintf(str,"%s00%d.tif",img_file_name_part,k+1); 
        break; 
      case 1:sprintf(str,"%s0%d.tif",img_file_name_part,k+1); 
        break; 
      default:sprintf(str,"%s%d.tif",img_file_name_part,k+1); 
        break; 
     } 
     printf("%s\n",str); 

     /* Loading Image using OpenCV */ 
     imgs=cvLoadImage(str,-1); 
     if(imgs==NULL) 
     { 
      printf("error in opening image \n"); 
      exit(1); 
     } 
     imgdata=(uchar *)imgs->imageData; 

     for(int j =0; j < ylen; j++) 
     { 
      for(int i =0; i < xlen; i++) 
      { 
       data[ k*xlen*ylen + j*xlen + i ] = imgdata[ j*xlen+i ]; 
      } 
     } 

     cvReleaseImage(&imgs); 
    } 

    /* populating `data` variable is done. So, calling `write_den` */ 
    if(write_den("test.den",data,xlen,ylen,zlen)==0) 
    { 
     printf("Error in creating den file\n"); 
     exit(1); 
    } 
    printf("Den file created\n"); 

} 

Questi sono l'elenco dei errori:

 
Error 3 error C2143: syntax error : missing ';' before 'type' c:\examples\denfile.c 358 1 MTP_TEST 
Error 4 error C2143: syntax error : missing ';' before 'type' c:\examples\denfile.c 358 1 MTP_TEST 
Error 5 error C2143: syntax error : missing ')' before 'type' c:\examples\denfile.c 358 1 MTP_TEST 
Error 6 error C2143: syntax error : missing ';' before 'type' c:\examples\denfile.c 358 1 MTP_TEST 
Error 7 error C2065: 'k' : undeclared identifier c:\examples\denfile.c 358 1 MTP_TEST 
Error 9 error C2065: 'k' : undeclared identifier c:\examples\denfile.c 358 1 MTP_TEST 
Error 10 error C2059: syntax error : ')' c:\examples\denfile.c 358 1 MTP_TEST 
Error 11 error C2143: syntax error : missing ';' before '{' c:\examples\denfile.c 359 1 MTP_TEST 
Error 12 error C2065: 'k' : undeclared identifier c:\examples\denfile.c 361 1 MTP_TEST 
Error 13 error C2065: 'k' : undeclared identifier c:\examples\denfile.c 370 1 MTP_TEST 
Error 14 error C2065: 'k' : undeclared identifier c:\examples\denfile.c 372 1 MTP_TEST 
Error 15 error C2065: 'k' : undeclared identifier c:\examples\denfile.c 374 1 MTP_TEST 
Error 16 error C2143: syntax error : missing ';' before 'type' c:\examples\denfile.c 388 1 MTP_TEST 
Error 17 error C2143: syntax error : missing ';' before 'type' c:\examples\denfile.c 388 1 MTP_TEST 
Error 18 error C2143: syntax error : missing ')' before 'type' c:\examples\denfile.c 388 1 MTP_TEST 
Error 19 error C2143: syntax error : missing ';' before 'type' c:\examples\denfile.c 388 1 MTP_TEST 
Error 20 error C2065: 'j' : undeclared identifier c:\examples\denfile.c 388 1 MTP_TEST 
Error 22 error C2065: 'j' : undeclared identifier c:\examples\denfile.c 388 1 MTP_TEST 
Error 23 error C2059: syntax error : ')' c:\examples\denfile.c 388 1 MTP_TEST 
Error 24 error C2143: syntax error : missing ';' before '{' c:\examples\denfile.c 389 1 MTP_TEST 
Error 25 error C2143: syntax error : missing ';' before 'type' c:\examples\denfile.c 390 1 MTP_TEST 
Error 26 error C2143: syntax error : missing ';' before 'type' c:\examples\denfile.c 390 1 MTP_TEST 
Error 27 error C2143: syntax error : missing ')' before 'type' c:\examples\denfile.c 390 1 MTP_TEST 
Error 28 error C2143: syntax error : missing ';' before 'type' c:\examples\denfile.c 390 1 MTP_TEST 
Error 29 error C2065: 'i' : undeclared identifier c:\examples\denfile.c 390 1 MTP_TEST 
Error 31 error C2065: 'i' : undeclared identifier c:\examples\denfile.c 390 1 MTP_TEST 
Error 32 error C2059: syntax error : ')' c:\examples\denfile.c 390 1 MTP_TEST 
Error 33 error C2143: syntax error : missing ';' before '{' c:\examples\denfile.c 391 1 MTP_TEST 
Error 34 error C2065: 'k' : undeclared identifier c:\examples\denfile.c 392 1 MTP_TEST 
Error 35 error C2065: 'j' : undeclared identifier c:\examples\denfile.c 392 1 MTP_TEST 
Error 36 error C2065: 'i' : undeclared identifier c:\examples\denfile.c 392 1 MTP_TEST 
Error 37 error C2065: 'j' : undeclared identifier c:\examples\denfile.c 392 1 MTP_TEST 
Error 38 error C2065: 'i' : undeclared identifier c:\examples\denfile.c 392 1 MTP_TEST 

Ho ricevuto questo tipo di errori tutto il giorno. A volte il codice viene compilato, mentre in altri casi no. È veramente noioso.

+0

Avete copiato/passato po 'di codice da un altro editor/browser web? Ho avuto problemi simili prima quando c'erano caratteri nascosti presenti nel codice incollato. –

+2

Senza offesa, ma non penso che il problema risieda in MSVC. –

+0

Quali flag della riga di comando stai passando al compilatore? – Mark

risposta

13

Si sta compilando un file .c, che per Microsoft Visual Studio significa che è necessario scrivere codice C89 (alias C90), non codice C99 o C++.

Ciò significa che è necessario dichiarare le variabili all'inizio di ogni blocco. Questo significa che non si può fare:

for (int k = 0; ... 

si deve dichiarare k all'inizio del blocco e fare:

for (k = 0; ... 
+0

Oppure compilarlo come codice C++. È anche tutto valido C++. +1. –

+0

@Billy: dove posso trovare le opzioni per impostare queste diverse lingue? – volpack

+0

@Charles Bailey: dove trovo le opzioni da impostare se dovrebbe usare c89/c99/C++? – volpack

2

Avete un punto e virgola mancante dopo una dichiarazione di classe/struct prima linea di 343?

Una cosa che puoi fare è provare un altro compilatore per vedere se ricevi un messaggio di errore diverso che ti parla di più. Ad esempio, c'è Comeau online.

Altrimenti, potresti avere qualche ladro #defines nel tuo codice o alcuni dei tuoi include? Dal momento che questo non accade sempre, qualcuno potrebbe giocarci brutti scherzi? Prova ad esaminare l'output preelaborato.

+0

No. controllato accuratamente Ho anche provato a cancellare solo questo codice e la compilazione. Compila bene. – volpack

+0

@JRL: Il primo errore è al primo ciclo for all'interno di questa funzione - penso che se fosse un punto e virgola di classe finale mancante ci sarebbe stato un errore quando int stato rilevato all'inizio della definizione della funzione. Ma un buon debug psichico - questa è la prima cosa che controllerei. +1. –

Problemi correlati