this is my first question on StackOverflow ! :) To be honest I'm about to destroy my whole setup.
My code is making me crazy.
My problem is, I am not able to fill a dynamic array with the return of a function. My goal here is, for each array box, fill it with a random value of 'randomizer'. I am not able to take the return of randomizer in the array box.
Here is the code:
main.c:
#include "functions.h"
#include "functions.c"
/* TP 3 - ESIEE-IT Rémy JARDIN */
int main() {
int saisie, i;
printf("Creation du Tableau. \nNombre de caractere du tableau : ");
scanf("%d", &saisie);
ArrayCreate(saisie);
// Affichage
return 0;
}
functions.h:
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include <stdio.h>
#include <stdlib.h>
int ArrayCreate(int saisie);
int randomizer();
int insereAIndice();
#endif
functions.c:
#include <stdio.h>
#include <stdlib.h>
int ArrayCreate(int saisie) {
int i;
int *Tab = (int *)malloc(saisie * sizeof(int));
if (Tab == NULL) {
printf("Not enough Memory");
exit (1);
}
for (i = 0; i < saisie; i++) {
Tab[i] = (randomizer + 1);
}
printf("\n Resultats : ");
for (i = 0; i < saisie; i++) {
printf("%d - ", *(Tab + i));
}
return 0;
}
int randomizer() {
//int x = rand() % (100 + 1);
return 1;
}
And the error is:
functions.c: In function 'ArrayCreate':
functions.c:12:8: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
Tab[i] = (randomizer+1);