C GLubyte 数组

标签 c arrays

我有这个问题。我手动初始化了下面代码中注释的数组,并且我想要一个函数来执行此操作,值是什么并不重要。我无法做到这一点,当我在函数末尾打印时,一切都是 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
// };

最佳答案

您将它们打印为 float

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

你应该将它们打印为整数

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

关于C GLubyte 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16176572/

相关文章:

c - 为什么给 ReadFileEx() 的回调没有收到正确的 OVERLAPPED 结构?

c - C-透明regex.h使用教程

javascript - 如何在数组中找到相同的元素及其值的总和

c - 字符串的第一个非重复字符

javascript - 按共同值对 javascript 对象进行分组

c - 连接来自 MPI 模拟的输出二进制文件

c++ - ffmpeg 在 libavutil 中缺少 config.h(没有这样的文件或目录)CodeBlocks

c - C 中的二叉搜索树出现奇怪的故障

javascript - 在sequelize中按长度对数组进行排序

php - 当输入字段的数量和名称发生变化时,如何确保 MySQL 插入的列匹配?