2013-10-13 71 views
0

嗯,這是我的代碼和我得到這個錯誤錯誤「sscanf_result」未聲明(在一次使用此功能)

在功能「主」:

411 [錯誤]「scanf_result」未申報(第一次使用在此功能)

41 1 [注]每個未聲明的標識符是爲它出現在

 #include <stdio.h> 
      #include <stdlib.h> 


     int main (int argc, char *argv[]) 

     { 
     int n; 
      float fl,fw,wh,ww,dh,dw; 
     float p,t; 
     float tl,tw,a; 
     float p1,p2,p3; 
      printf("What's the width of the floor?"); 
      scanf ("%d", &fw); 
      printf("What's the length of the floor?"); 
      scanf ("%d", &fl); 
      printf("What's the height of the wall?"); 
       scanf ("%d", &wh); 
       printf("What's the width of the wall?"); 
      scanf ("%d", &ww); 
     printf("What's the width of the door?"); 
      scanf ("%d", &dw); 
     printf("What's the height of the door?"); 
     scanf ("%d", &dh); 
      a=fw*fl+(wh*ww)*3-(dh*dw); 
     p1=a*22; 
     p2=a*23.80; 
      p3=a*14; 

      char line[100]; 
      int answer; 
     answer = -1; 
     while (answer != 0) 
     { 
     printf ("\nWhat tiles do you want?:\n"); 
      printf (" [1] 20sm X 30sm."); 
     printf (" [2] 30sm X 41,6sm"); 
     printf (" [3] 25sm X 33sm"); 
     printf ("\nWhat do you want to do? [0 for nothing] "); 
      fgets (line, sizeof(line), stdin); 
       scanf_result = scanf (line, "%d", &answer); 
      if ((scanf_result == 0) | (scanf_result == EOF)) 
      { 
       printf ("\n *** 1 - 2 or 3! ***\n"); 
      answer = -1; 
      } 
      switch (answer) 
     { 
        case 0: 
      break; 
     case 1: 
       printf(" Total price = %.2f lv \n",p1); 
     break; 
      case 2: 
     printf(" Total price = %.2f lv \n",p2); 
      break; 
      case 3: 
      printf(" Total price = %.2f lv \n",p3); 
      break; 
      default: 
      break; 
       } 

     } 

       system("PAUSE"); 
      return 0;  
     } 
+2

修復您的代碼格式和縮進。 –

+0

請不要破壞你自己的問題。 –

回答

0

作爲錯誤信息清楚地描述的那樣,每個療法功能只報告一次e在您的程序中沒有聲明scanf_result變量。在聲明部分

int scanf_result; 

來修復錯誤:

放一個。

0
 scanf_result = scanf (line, "%d", &answer); 

scanf()用法是錯誤的。您需要改爲sscanf()

scanf()函數應從標準輸入流stdin讀取。 sscanf()函數應從字符串line中讀取。

[錯誤]未聲明(在一次使用此功能)

錯誤地描述你所缺少的是什麼 'scanf_result'。

scanf_result申報

sscanf()返回整數

聲明爲整數變量。

相關問題