C - 从链表打印 SDL TTF



当我从链表(从第一个链接结构)尝试使用 sdl 进行 printf 时,程序停止了。

这是结构:

typedef struct ranklist {
    int point;
    char* name;
    struct ranklist *next;
} ranklist;

此函数从文件中读取(结果.txt)

ranklist* rank_read (ranklist *r, ranklist *first){
    FILE *fp = fopen("result.txt","r");
    int name_length;
    ranklist  *curr;
    int point;

    while(1==fscanf(fp, "%d", &point)){
        r = malloc(sizeof(*r));
        r->next = NULL;
        r->point = point;
        name_length = how_many_letter(fp);
        r->name = malloc(name_length + 1);
        fscanf(fp, "%s", r->name);
        if(first == NULL)
            first = curr = r;
        else
            curr = curr->next = r;
    }
    fclose(fp);
    return first;
}

这是 sdl 打印功能:

void sdl_printing (SDL_Surface *screen, char arr[], TTF_Font *font, int x, int y){
SDL_Color white = {255, 255, 255};
SDL_Rect where = { 0, 0, 0, 0 };
SDL_Surface *subtitle;
subtitle = TTF_RenderUTF8_Blended(font, arr, white);
    where.x = x;
    where.y = y;
    SDL_BlitSurface(subtitle, NULL, screen, &where);
    SDL_FreeSurface(subtitle);
}

我尝试了这个,但它不起作用:

sdl_printing (screen, first->name , font, 100, 200); //the last two is x and y

然后(如果有效)到链表中的另一个结构的步骤:

first = first->next;

我不知道为什么...

您的where目标矩形的宽度为零,高度为零(第 3 和第 4 个组件)。您需要设置宽度和高度才能看到任何内容。目前,您正在拼凑成一个完全平坦的矩形。

试试这个看看它是否有效:

SDL_BlitSurface(subtitle, NULL, screen, NULL);

相关内容

  • 没有找到相关文章

最新更新