我正在尝试建立一个购物中心,但我无法在功能之间跳转 我已经尝试过 goto 语句,继续一切,请帮助一切都会起作用
这是我的代码
#include <stdio.h>
int Verify;
struct Worker
{
int ID;
int Password;
}i;
void Workers_data()
{
struct Worker Sahaj;
struct Worker Sparsh;
struct Worker Ramu;
struct Worker Shamu;
strcpy(Sahaj.ID,1);
strcpy(Sahaj.Password,951);
strcpy(Sparsh.ID,2);
strcpy(Sparsh.Password,223);
strcpy(Ramu.ID,3);
strcpy(Ramu.Password,2334);
strcpy(Shamu.ID,4);
strcpy(Shamu.Password,142);
}
void login()
{
printf("||||||||||||||||Welcome are you a Customer or a Worker|||||||||||||||||||");
prinf("Press 1 for Worker and 2 for Customer\n")
scanf("%d",Verify);
if (Verify = 1)
{
goto Batman;
}
else if (Verify = 2)
{
goto Superman;
}
}
void Batman()
{
prinf("Please write your id below\n");
scanf("%d",&i.ID);
printf("Please write your password below\n");
scanf("%d",&i.Password);
}
请帮帮我 提前致谢
最佳答案
我认为为了将控制权转移到其他函数,您只需要像这样调用它:
if (Verify == 1)
{
Batman();
}
else if (Verify == 2)
{
Superman();
}
无需转到此处。但是您需要将参数传递给函数,以便它可以处理这些值。
您的代码有一些问题:
1.) 在比较时您使用的是 =
而不是 ==
2.) scanf("%d", verify);
您需要在此处传递地址:&Verify
3.) 您尚未声明任何用于获取输入的结构变量/数组。您还应该为其添加一个变量/数组,您应该在 Batman()
中通过 scanf 获取输入:
i workers[100];
int nWorkers;
4.) printf
方法的一些拼写错误。
5.) 不使用 typedef
创建结构别名:
typedef struct Worker
{
int ID;
int Password;
}i;
6.) Superman() 方法似乎没有在任何地方定义(也许你的代码仍然是 WIP)。但是 Batman() 可以这样改进:
void Batman()
{
printf("Please write your id below\n");
scanf("%d",&workers[nWorkers].ID); // Initialize it to zero in main()
printf("Please write your password below\n");
scanf("%d",&workers[nWorkers].Password);
nWorkers++;
}
关于c - 如何在函数之间跳转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55793227/