0

我有这个问题。我手动初始化了下面代码中注释的数组,我想要一个函数来做到这一点,不管值是什么。我无法做到这一点,当我在函数末尾打印时,一切都是 0。对此有任何想法吗?

GLubyte *createGraphIndices(int size){


    GLubyte * graphIndices = malloc(size * sizeof(GLubyte));
    int i;

    for(i = 0; i < (size/2)-1; ++i){ // até
        graphIndices[i] = i;
    }
    for(i = (size/2)-1; i < size-2; ++i){ // até
        graphIndices[i] = i;
    }

    for(i = 0; i < size; ++i){ // até
        fprintf(stderr, "%f\n", graphIndices[i]);
    }
    return graphIndices;
}
// GLubyte graphIndices[] = {
// 
//  0,1,
//  1,2,
//  2,3,
//  3,4,
//  4,5,
//  5,6,
//  6,7,
//  7,8,                
//  9,10,
//  10,11,
//  11,12,
//  12,13,
//  13,14,
//  14,15,
//  15,16,
//  16,17
// };
4

1 回答 1

1

您将它们打印为浮点数

    fprintf(stderr, "%f\n", graphIndices[i]);

你应该将它们打印为整数

    fprintf(stderr, "%d\n", graphIndices[i]);
于 2013-04-23T18:41:06.463 回答