Project

General

Profile

Revision 183

can reduce letter size; working on increasing

View differences:

xpm_utils.c
32 32
        sscanf(line_buf, "%d %d %d %d", &w, &h, &num_colors, &chars_per_pixel);
33 33
        ret = malloc((1+num_colors+h)*sizeof(char*));
34 34
    }
35
    ret[0] = malloc((sz+1)*sizeof(char));
35
    ret[0] = malloc((sz+1)*sizeof(char)); if(ret[0] == NULL){ free(ret); return NULL; }
36 36
    strcpy(ret[0], line_buf);
37
    
37

  
38 38
    for(int i = 1; i < 1+num_colors+h; ++i){
39 39
        sz = getline(&line_buf, &len, f);
40 40
        ret[i] = malloc((sz+1)*sizeof(char));
41
        if(ret[i] == NULL){
42
            for(int j = 0; j < i; ++j)
43
                free(ret[i]);
44
            free(ret);
45
            return NULL;
46
        }
41 47
        strcpy(ret[i], line_buf);
42 48
        ret[i][sz-1] = '\0';
43
        printf("%s\n", ret[i]);
44 49
    }
45 50
    fclose(f); f = NULL;
46 51
    return ret;

Also available in: Unified diff