2014-05-05 104 views
0

我在實際獲取函數對不同變量執行操作時遇到了問題。我不知道是不是因爲我錯誤地定義了它,而是希望得到幫助。C函數調用問題

#include <stdio.h> 

int dmv(int x); 

int main() 
{ 
    printf("Welcome to DMV simulator 2014! \n"); 
    printf("Come forward first client"); 
    int z; 
    int d; 
    int f; 
    int g; 
    int h; 
    int j; 
    int e; 
    int q; 
    int s; 
    dmv(int z); 
    printf("Are there anymore people?"); 
    printf("If 'yes' say so otherwise say 'no'"); 
    int option; 
    if(option == "yes") 
    { 
     dmv(int f); 
    } 
    else 
    { 
      printf("We're closing");  
    } 
    printf("Are there anymore people?"); 
    printf("If 'yes' say so otherwise say 'no'"); 
    if(option == "yes") 
    { 
     dmv(int d); 
    } 
    else 
    { 
     printf("We're closing"); 
    } 
    printf("Are there anymore people?"); 
    printf("If 'yes' say so otherwise say 'no'"); 
    if(option == "yes") 
    { 
     dmv(int g); 
    } 
    else 
    { 
     printf("We're closing"); 
    } 
    printf("Are there anymore people?"); 
    printf("If 'yes' say so otherwise say 'no'"); 
    if(option == "yes") 
    { 
     dmv(int h); 
    } 
    else 
    { 
     printf("We're closing"); 
    } 
    printf("Are there anymore people?"); 
    printf("If 'yes' say so otherwise say 'no'"); 
    if(option == "yes") 
    { 
     dmv(int j); 
    } 
    else 
    { 
     printf("We're closing"); 
    } 
    printf("Are there anymore people?"); 
    printf("If 'yes' say so otherwise say 'no'"); 
    if(option == "yes") 
    { 
     dmv(int e); 
    } 
    else 
    { 
     printf("We're closing"); 
    } 
    printf("Are there anymore people?"); 
    printf("If 'yes' say so otherwise say 'no'"); 
    if(option == "yes") 
    { 
     dmv(int q); 
    } 
    else 
    { 
     printf("We're closing"); 
    } 
    printf("Are there anymore people?"); 
    printf("If 'yes' say so otherwise say 'no'"); 
    if(option == "yes") 
    { 
     dmv(int s); 
    } 
    else 
    { 
     printf("We're closing"); 
    } 
    printf("Alright we're closing!"); 

    return(0); 
} 

int dmv(int x) 
{ 
    pritnf("Enter your name \n"); 
    char name; 
    char Birthday; 
    printf("Enter your DOB"); 
    scanf("%c" , name); 
    scanf("%c" , Birthday); 
    printf("Here is your lisence %d" , name); 
} 

這裏是我在cygwin得到的錯誤。

Functionography.c:19: error: parse error before "int" 
Functionography.c:23: warning: comparison between pointer and integer 
Functionography.c:25: error: parse error before "int" 
Functionography.c:34: warning: comparison between pointer and integer 
Functionography.c:36: error: parse error before "int" 
Functionography.c:45: warning: comparison between pointer and integer 
Functionography.c:47: error: parse error before "int" 
Functionography.c:56: warning: comparison between pointer and integer 
Functionography.c:58: error: parse error before "int" 
Functionography.c:67: warning: comparison between pointer and integer 
Functionography.c:69: error: parse error before "int" 
Functionography.c:77: warning: comparison between pointer and integer 
Functionography.c:79: error: parse error before "int" 
Functionography.c:88: warning: comparison between pointer and integer 
Functionography.c:90: error: parse error before "int" 
Functionography.c:99: warning: comparison between pointer and integer 
Functionography.c:101: error: parse error before "int" 
+0

什麼是線19的目的是什麼? –

+0

你應該嘗試一個叫做* loops *的新概念。 –

+0

這裏有很多問題,包括一些非常基本的語法問題。 – crashmstr

回答

2

該函數應該被調用,如:

dmv(z); 
0

由於DMV函數的類型爲int,則它應該返回一些整數值。否則,對於dmv函數使用void return類型。

0

嗯,有問題有很多在這裏:

  • 您複製/粘貼代碼。你永遠不應該那樣做。這就是爲什麼函數和循環存在!

  • dmv(int z)是一個聲明,而不是一個調用。一旦你的函數被聲明,你只需要把正確的類型的變量。 (dmv(z)

  • Your scanf are not good。無論是使用字符數組(char birthday[5])或指針發送到您的變量(scanf("%c", &birthday);

  • 你不需要抓什麼DMV正在恢復。要麼它返回任何結果(void dmv)或做一些事情的結果。

  • 你試圖讓與scanf("%c")一個字符串,它會返回一個字符,而不是字符串。

  • 您嘗試打印字符串printf("%d"),將打印十進制整數。

  • 可以聲明的多個相同類型的可變這樣的:

    INT一個, B, C, d;

  • 在做printf時,不要忘記在最後添加\ n,否則輸出將不可讀。它可以處理「h」,「i」或「a」,或者任何在ascii表中,但不是「Hello」或其他多個字符。

  • 就這樣,如果你回答否,你的代碼將不會在意。首先是因爲你不問任何用戶輸入,其次是因爲你不能夠輸入==一個字符串,第三個是因爲你要麼指向...的下一個分支......下一個「迭代」。

在這裏,改良後的代碼:

#include <stdio.h> 

int dmv(int x); 

int main() 
{ 
    printf("Welcome to DMV simulator 2014! \n"); 
    printf("Come forward first client"); 
    int i = 0, 
     end = 0; 
    int clients[5]; 
    char option[4] = ""; 
    do 
    { 
     dmv(int z); 
     printf("Are there anymore people?"); 
     printf("If 'yes' say so otherwise say 'no'"); 
     scanf("%s", cache); 
     if(strcmp(cache, "yes")) 
     { 
      client[i] = dmv(f); 
     } 
     else 
     { 
       printf("We're closing"); 
       end = 1; 
     } 
    }while(i < 5 || end = 1); 

    return(0); 
} 

int dmv(int x) 
{ 
    pritnf("Enter your name \n"); 
    char name[30]; 
    char Birthday[11]; 
    printf("Enter your DOB"); 
    scanf("%s" , name); 
    scanf("%s" , Birthday); 
    printf("Here is your lisence %s" , name); 
}