C函数调用问题

时间:2014-05-05 13:21:27

标签: c function

我实际上无法让函数执行不同的变量。我不知道是不是因为我错误地定义了它,但是我们将不胜感激。

#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"

3 个答案:

答案 0 :(得分:2)

应该调用该函数:

dmv(z);

答案 1 :(得分:0)

由于dmv函数的类型为int,因此应返回一些整数值。否则使用void返回类型为dmv函数。

答案 2 :(得分:0)

嗯,这里有很多问题:

  • 您复制/粘贴代码。你永远不应该这样做。这就是函数和循环存在的原因!

  • dmv(int z)是声明,而不是电话。声明函数后,只需输入正确的变量即可。 (dmv(z)

  • 你的scanf不好。使用char数组(char birthday[5])或将指针发送到变量(scanf("%c", &birthday);

  • 你不知道dmv正在返回什么。要么它不返回任何内容(void dmv),要么对结果做一些事情。

  • 您尝试使用scanf("%c")获取字符串,它将返回一个字符,而不是字符串。

  • 您尝试使用printf("%d")打印字符串,该字符串将打印十进制整数。

  • 您可以声明多个相同类型的变量,如下所示:

    int a,     b,     C,     d;

  • 执行printf时,不要忘记在末尾添加\ n,否则输出将无法读取。

  • char是一个简单的字符,它可以处理&#34; h&#34;,&#34; i&#34;或&#34; a&#34;或ascii表中的任何内容,但不是&#34;你好&#34;或其他多重角色。

  • 实际上,如果您回答否,您的代码将无关紧要。首先是因为你不问任何用户输入,第二个因为你不能==一个字符串,第三个是因为你要么指向你的分支......下一个&#34;迭代&#34;。

这里改进了代码:

#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);
}