当我从链接列表(来自第一个链接结构)尝试使用sdl的printf时,程序停止了。
这是结构:
typedef struct ranklist {
int point;
char* name;
struct ranklist *next;
} ranklist;
此函数从文件(result.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;
我不知道为什么......
答案 0 :(得分:0)
您的where
目标矩形的宽度为零,高度为零(第3和第4个组件)。您需要设置宽度和高度才能看到任何内容。目前你正在进入一个完全扁平的矩形。
试试看它是否有效:
SDL_BlitSurface(subtitle, NULL, screen, NULL);