2014-05-05 100 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); 
}