我尝试将存在的字符串和整数分配给数组,但它一直在说核心倾倒
我已经知道for循环中有问题,但是我看不出为什么它不为数组分配了字符串。我刚刚开始学习编码。任何帮助都非常感谢!
#include<stdio.h>
#include<cs50.h>
#include<string.h>
typedef struct
{
string name;
int count;
}
people;
int main (int argc, string argv[])
{
//the number of candidates is (argc - 1)
int grossnumber = argc - 1;
people candidate [grossnumber];
for (int n =1; n <= grossnumber; n++)
{
**candidate[n].name = argv[n];
candidate[n].count = 0;**
}
}
I already knew there is something wrong within the for loop, but I can't see why it doesn't assign the string already existed to the array. I just started learning coding. Any help is much appreciated!
#include<stdio.h>
#include<cs50.h>
#include<string.h>
typedef struct
{
string name;
int count;
}
people;
int main (int argc, string argv[])
{
//the number of candidates is (argc - 1)
int grossnumber = argc - 1;
people candidate [grossnumber];
for (int n =1; n <= grossnumber; n++)
{
**candidate[n].name = argv[n];
candidate[n].count = 0;**
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论