我在让函数在不同的变量上执行时遇到了问题。我不知道是不是因为我对它的定义不正确,但如果能得到帮助,我将不胜感激。
#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"发布于 2014-05-05 21:25:01
应该像这样调用函数:
dmv(z);发布于 2014-05-05 21:30:43
由于dmv函数的类型为int,因此它应该返回某个整数值。否则,对dmv函数使用void返回类型。
发布于 2014-05-05 21:42:40
好吧,这里有很多问题:
dmv(int z)是一个声明,而不是一个调用。一旦你的函数被声明了,你只需要放入正确的变量类型。(dmv(z))char birthday[5]),要么将指针发送到您的变量dmv,不要捕获dmv返回的内容。要么不返回任何内容(void dmv),要么对结果做一些处理。scanf("%c")获取字符串,它将返回字符,而不是字符串。printf("%d")打印字符串,这将打印一个十进制整数。当做unreadable.
==字符串,第三是因为您的if分支指向...下一个"iteration".下面是改进后的代码:
#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);
}https://stackoverflow.com/questions/23473591
复制相似问题