C语言报错运行不了,不知道怎么改

题目
世界杯小组赛分组题目描述:世界杯是每四年的一个热门话题,请用C语言实现世界杯的小组分组。接下来才是你应该关注的重点:参赛队:英格兰、法国、德国、意大利、西班牙、荷兰、葡萄牙、克罗地亚、土耳其、俄罗斯、瑞典、捷克、塞尔维亚、加纳、科特迪瓦、突尼斯、尼日利亚、喀麦隆、日本、韩国、澳大利亚、伊朗、美国、墨西哥、哥斯达黎加、洪都拉斯、巴西、阿根廷、巴拉圭、智利、乌拉圭、厄瓜多尔。世界杯的小组分组规则如下:有八只种子球队,分别是:乌拉圭队、西班牙队、德国队、阿根廷队、哥伦比亚队、比利时队、瑞士队以及东道主巴西队。这八只球队一定分别在A——H八个组中(八只球队不能碰面)。小组分为A——H一共八个小组。分组结果按行输出。每个小组四个球队。(参考循环赛)。

提示:1.可以用链表指针或者结构体数组;2.随机数;3.也许你能做到我没有想到的

目前代码

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define T League
typedef struct T *T;
#define TreeHeigh 5

char *Other[] = {"英格兰","意大利","葡萄牙","克罗地亚","土耳其","瑞典","捷克","塞尔维亚","加纳","科特迪瓦","突尼斯","尼日利亚","喀麦隆","日本","韩国","澳大利亚","伊朗","美国","墨西哥","哥斯达黎加","洪都拉斯","巴拉圭","智利","厄瓜多尔"};

char *Send[] = { "乌拉圭","西班牙","德国","阿根廷","荷兰","法国","巴西","俄罗斯"};
int F_Send[ 8 ];
int F_Other[ 24 ];

struct T{
int Score;
int Heigh;
T Left;
T Right;
char *Name;
};

void INIT( T *Root, int Heigh );

void Print( T Root );

int main( void )
{
T Root;
int heigh;

heigh = 0;

Root = NULL;
INIT( &Root, heigh );
Print( Root );


return 0;

}

void INIT( T *Root, int Heigh )
{
int f;
static int g = -1;
srand( ( unsigned )time( NULL ) );
if( NULL == *Root )
{
T new = ( T )malloc( sizeof( struct T ) );
if( NULL == new )
exit( EXIT_FAILURE );
new->Left = NULL;
new->Right = NULL;
new->Name = NULL;
new->Score = -1;
new->Heigh = Heigh;
*Root = new;
}

if( TreeHeigh == ( *Root )->Heigh )
{
    ++g;
    if( 0 == g % 4 )
    {
        while( 1 )
        {        
            f = rand( ) % 8;
            if( 0 == F_Send[ f ] )
            {
                ( *Root )->Name = Send[ f ];
                F_Send[ f ] = 1;
                break;
            }
        }
    }
    else
    {
        while( 1 )
        {
            f = rand() % 24;
            if( 0 == F_Other[ f ] )
            {
                ( *Root )->Name = Other[ f ];
                F_Other[ f ] = 1;
                break;
            }
        }
    }

}

if( TreeHeigh == Heigh )
    return;

INIT( &(*Root)->Left, Heigh + 1 );
INIT( &(*Root)->Right, Heigh + 1 );

}

void Print( T Root )
{
static int g = 0;
static char ch = 'A';

if( NULL == Root )
    return;
if( NULL != Root->Name )
{
    if( 0 == g % 4 )
        printf( "%c\n", ch++);
    printf( "%s ", Root->Name );
    ++g;
    if( 0 == g % 2 )
        printf( "\n" );
}
Print( Root->Left );
Print( Root->Right );

}

  • 我整理了一下代码,编译通过,运行正常
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define TreeHeigh       5

typedef struct tree_s tree_t;
struct tree_s {
    int Score;
    int Heigh;
    tree_t *Left;
    tree_t *Right;
    const char *Name;
};

const char *Other[] =
{
    "英格兰","意大利","葡萄牙","克罗地亚","土耳其","瑞典","捷克","塞尔维亚","加纳",
    "科特迪瓦","突尼斯","尼日利亚","喀麦隆","日本","韩国","澳大利亚","伊朗","美国",
    "墨西哥","哥斯达黎加","洪都拉斯","巴拉圭","智利","厄瓜多尔" 
};
const char *Send[] = { "乌拉圭","西班牙","德国","阿根廷","荷兰","法国","巴西","俄罗斯" };
int F_Send[8];
int F_Other[24];

void tree_init(tree_t **root, int heigh);
void tree_print(tree_t *root);

int main(void)
{
    tree_t *root;
    int heigh;

    heigh = 0;

    root = NULL;
    tree_init(&root, heigh);
    tree_print(root);
    return 0;
}

void tree_init(tree_t **root, int Heigh)
{
    int f;
    static int g = -1;
    srand((unsigned)time(NULL));
    if (NULL == *root)
    {
        tree_t *item = (tree_t *)malloc(sizeof(tree_t));
        if (NULL == item)
            exit(EXIT_FAILURE);
        item->Left = NULL;
        item->Right = NULL;
        item->Name = NULL;
        item->Score = -1;
        item->Heigh = Heigh;
        *root = item;
    }

    if (TreeHeigh == (*root)->Heigh)
    {
        ++g;
        if (0 == g % 4)
        {
            while (1)
            {
                f = rand() % 8;
                if (0 == F_Send[f])
                {
                    (*root)->Name = Send[f];
                    F_Send[f] = 1;
                    break;
                }
            }
        }
        else
        {
            while (1)
            {
                f = rand() % 24;
                if (0 == F_Other[f])
                {
                    (*root)->Name = Other[f];
                    F_Other[f] = 1;
                    break;
                }
            }
        }

    }

    if (TreeHeigh == Heigh)
        return;

    tree_init(&(*root)->Left, Heigh + 1);
    tree_init(&(*root)->Right, Heigh + 1);
}
void tree_print(tree_t *root)
{
    static int g = 0;
    static char ch = 'A';

    if (NULL == root)
        return;
    if (NULL != root->Name)
    {
        if (0 == g % 4)
            printf("%c\n", ch++);
        printf("%s ", root->Name);
        ++g;
        if (0 == g % 2)
            printf("\n");
    }
    tree_print(root->Left);
    tree_print(root->Right);
}
  • 运行效果(VS 2022)

img

报的什么错

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#define T League
typedef struct T *T;
#define TreeHeigh 5

char *Other[] = {"英格兰","意大利","葡萄牙","克罗地亚","土耳其","瑞典","捷克","塞尔维亚","加纳","科特迪瓦","突尼斯","尼日利亚","喀麦隆","日本","韩国","澳大利亚","伊朗","美国","墨西哥","哥斯达黎加","洪都拉斯","巴拉圭","智利","厄瓜多尔"};
char *Send[] = { "乌拉圭","西班牙","德国","阿根廷","荷兰","法国","巴西","俄罗斯"};
int F_Send[ 8 ];
int F_Other[ 24 ];

struct T{
    int Score;
    int Heigh;
    T Left;
    T Right;
    char *Name;
};

void INIT( T *Root, int Heigh );

void Print( T Root );

int main( void )
{
    T Root;
    int heigh;

    heigh = 0;
     
    Root = NULL;
    INIT( &Root, heigh );
    Print( Root );
    return 0;
}

void INIT( T *Root, int Heigh )
{
    int f;
    static int g = -1;
    srand( ( unsigned )time( NULL ) );
    if( NULL == *Root )
    {
    T new = ( T )malloc( sizeof( struct T ) );
    if( NULL == new )
    exit( EXIT_FAILURE );
    new->Left = NULL;
    new->Right = NULL;
    new->Name = NULL;
    new->Score = -1;
    new->Heigh = Heigh;
    *Root = new;
    }

    if( TreeHeigh == ( *Root )->Heigh )
    {
        ++g;
        if( 0 == g % 4 )
        {
            while( 1 )
            {        
                f = rand( ) % 8;
                if( 0 == F_Send[ f ] )
                {
                    ( *Root )->Name = Send[ f ];
                    F_Send[ f ] = 1;
                    break;
                }
            }
        }
        else
        {
            while( 1 )
            {
                f = rand() % 24;
                if( 0 == F_Other[ f ] )
                {
                    ( *Root )->Name = Other[ f ];
                    F_Other[ f ] = 1;
                    break;
                }
            }
        }
     
    }
     
    if( TreeHeigh == Heigh )
        return;
     
    INIT( &(*Root)->Left, Heigh + 1 );
    INIT( &(*Root)->Right, Heigh + 1 );
}

void Print( T Root )
{
    static int g = 0;
    static char ch = 'A';

    if( NULL == Root )
        return;
    if( NULL != Root->Name )
    {
        if( 0 == g % 4 )
            printf( "%c\n", ch++);
        printf( "%s ", Root->Name );
        ++g;
        if( 0 == g % 2 )
            printf( "\n" );
    }
    Print( Root->Left );
    Print( Root->Right );
}

img


所以问题是什么呢

并没有什么错 如果你要输入输出的话 代码第一行加上这个

#define _CRT_SECURE_NO_WARNINGS