我尝试将存在的字符串和整数分配给数组,但它一直在说核心倾倒

发布于 2025-02-03 01:46:41 字数 504 浏览 1 评论 0原文

我已经知道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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文