C initialisation du tableau de tableaux

J'ai ce problème. J'ai besoin d'avoir un tableau de float tableaux pour stocker avant de m'exécuter certaines fonctions. Comment puis-je y parvenir, car je ne peux pas initialiser un tableau withut un non constante? Je dois faire une fonction qui permet de créer ce tableau avec la fonction malloc puis retour dans, et de confier à un pointeur?

typedef struct
{
    float RGBA[4];
} graphColors;

J'ai besoin d'avoir un tableau de grapColors. Je suis désolé pour mon manque de connaissance, je suis un programmeur Java et de la nécessité de travailler avec des C maintenant.

EDIT:

graphColors *initializeGraphColors(){
    graphColors *gp;
    int i;
    float HI = 1.0f;
    float LO = 0.0f;

    float temp[] = {1.0f, 1.0f, 1.0f, 0.0f};
    gp = (graphColors *) malloc(nrOfLines * sizeof(graphColors));

    for(i = 0;i < nrOfLines; i++){
        gp[i].RGBA[0] = LO + (float)rand()/((float)RAND_MAX/(HI-LO));
        gp[i].RGBA[1] = LO + (float)rand()/((float)RAND_MAX/(HI-LO));
        gp[i].RGBA[2] = LO + (float)rand()/((float)RAND_MAX/(HI-LO));
        gp[i].RGBA[3] = 0.0f;
    }
    return gp;
}

Puis dans ma classe:

graphColors *gc;
gc = initializeGraphColors();

Obtenir cette erreur:

error C2040: 'gc' : 'graphColors *' differs in levels of indirection from 'graphColors'
  • Vous n'avez pas besoin de jeter la valeur de retour de malloc dans un programme C.
InformationsquelleAutor Nick Spot | 2013-04-26