'Find three or more consecutive characters in the same struct in C

I define a struct.

struct test
{
    char name[10];
    int num;
}temp[20];

I want to only output the data with the same name and three consecutive num or more in temp[20]. for example,the data of the temp[20] are as follows:

    temp[0] = { "a",0 };
    temp[1] = { "b",1 };
    temp[2] = { "a",2 };
    temp[3] = { "b",2 };
    temp[4] = { "a",3 };
    temp[5] = { "b",3 };
    temp[6] = { "a",4 };
    temp[7] = { "c",1 };
    temp[8] = { "c",2 };
    temp[9] = { "a",5 };
    ........

the output is

    temp[2] = { "a",2 };
    temp[4] = { "a",3 };
    temp[6] = { "a",4 };
    temp[9] = { "a",5 };
    temp[1] = { "b",1 };
    temp[3] = { "b",2 };
    temp[5] = { "b",3 };

I can only use a triple for loop to output data with the same name and three consecutive num,but four consecutive num can`t output.My code are as follows:

for (int i = 0; i < 20; i++)
    {
        for (int j = i + 1;j < 20;j++) {
            if ((strcmp(temp[i].name, temp[j].name) == 0) && (temp[j].num - temp[i].num == 1))
            {
                for (int k = 0; k < 20; k++)
                {
                    if ((strcmp(temp[k].name, temp[j].name) == 0) && (temp[k].num - temp[j].num == 1)) {
                        printf("%s,%d", temp[i].name, temp[i].num);
                        printf("%s,%d", temp[j].name, temp[j].num);
                        printf("%s,%d", temp[k].name, temp[k].num);
                    }
                }
            }
        }
    }

what could I do?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source