2014-12-05 110 views
0

当我尝试从链接列表(从第一个链接的结构)sdl printf,程序停下来。sdl ttf打印链接列表

这是如下结构:

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

where目标矩形具有零宽度和零高度(第3和第4个分量)。您需要设置宽度和高度以查看任何内容。目前,你正在变成一个完全平坦的矩形。

试试这个,看看它的工作原理:

SDL_BlitSurface(subtitle, NULL, screen, NULL); 
+0

SDL_BlitSurface()不会做软件缩放,因此不使用目标矩形的宽度和高度。 SDL_RenderCopy()虽然。 – 2014-12-05 15:01:36

+0

@JonnyD是的,你说得对。对于OP:检查是否可以打印像“test”这样的简单字符串,也许您尚未正确初始化SDL或曲面。 – ysalmi 2014-12-05 21:18:11