简体   繁体   English

如何从结构数组中删除字符串

[英]How to delete a string from struct array

I'm doing a project for displaying the table of a soccer championhip.我正在做一个显示足球锦标赛表格的项目。 The part that I'm struggling with is the deletion of a club by entering his name.我正在努力解决的部分是通过输入他的名字来删除俱乐部。 I have, for example, the following record:例如,我有以下记录:

struct soccer_table_properties
{
    char name[LENGTH];
    int gscored;
    int gconceded;
    int points;
};

If I enter the name club in order to delete it, I also delete his gained points, gol scored and conceded, but I can't figure that.如果我进入名称俱乐部以删除它,我也会删除他的得分,戈尔得分和失球,但我无法计算。 Can You help me, please?你能帮我吗?

For the deletion part, I tried this implementation but it doesn't work.对于删除部分,我尝试了这个实现,但它不起作用。

do {
        printf("Enter the club name: \n");
        scanf("%s", club[i].name);

        for (j = 0; j < i; j++) {
            res = strcmp(club[j].name, club[i].name);
            if (res == 0){
                true = 1;
                strcpy(club[j].name, 0);
                i--;
            }
        }

        if (true == 0) {
            printf("wrong number \n");
        }
   } while (true == 0);

I guess you are using a array of structures.so to delete an element you must move all the elements to right of element ie left shift all of them after the element.or else if are making it 0 to represent deletion then it should be fine.in the code use "0".我猜你正在使用一个结构数组。所以要删除一个元素,你必须将所有元素移动到元素的右侧,即在元素之后将所有元素左移。否则如果将其设为 0 表示删除,那么它应该没问题.在代码中使用“0”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM