I have to do a C project, but I never studied C. The compiler complains about a "Cast to pointer from integer of different size". Can you explain the nature of the problem and how I can fix it?
Here's my code :
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <pthread.h>
#include <fcntl.h>
#include <time.h>
#include <stdint.h>
#include <pthread.h> //-lpthread commande
FILE* resultat=NULL; //déclaration d'un fichier nommé resultat qui contiendra les résultats issus du calcul des 3 fonctions
int T[199]; //déclaration d'un tableau de taille 199 en statique
static void *MARIT (void* i) //fonction qui calcul la moyenne arithmétique
{
int s,j;
int M1=0;
//boucle qui calcul la moyenne arithmétique
for (j=0;j<=150;j++)
{
s=(j*M1+T[j]);
M1=s/(j+1);
fprintf(resultat," Moyenne 1: %d \n",M1);//on écrit le résultat dans le fichier nommé resultat
}
return NULL;
}
static void *MQUAD (void* i) //fonction qui calcul la moyenne quadratique
{
int s,j;
int M2=0;
//boucle qui calcul la moyenne quadratique
for (j=0;j<=150;j++)
{
s=s+((T[j])*(T[j]));
M2=sqrt(s/(j+1));
fprintf(resultat," Moyenne 2: %d \n",M2);
}
return NULL;
s=0;
}
static void *SCUB (void* i) //fonction qui calcul la somme des nombres cubique
{
int s,j;
int M3=0;
//boucle qui calcul la somme des nombres cubique
for (j=0;j<=150;j++)
{
s=M3+((T[j])*(T[j])*(T[j]));
M3=s;
fprintf(resultat," Moyenne 3: %d \n",M3);
}
return NULL;
}
int main (int argc, char* argv[]) {
pthread_t tid1; //déclaration de 3 thread
pthread_t tid2;
pthread_t tid3;
int M1,M2,M3;
int f,i;
int N=199;
i=atoi(argv[1])-1; //remplace chaine de caractère par un entier (ici on demande à l'utilisateur d'entrer N)
srand(time(NULL)); // initialisation de rand
while (f<=N){ //Boucle qui permet de générer N nombres aléatoire stocké dans T
T[f]= rand()%100; //N est demandé à l'utilisateur pour savoir combien il souhaite générer de nombres aléatoire
printf("%i \n",T[f]);
f++;
}
resultat=fopen("Resultatthread1.txt","w+"); //Création du fichier Resultat
//creation des thread, 3 thread pour 3 fonctions
pthread_create(&tid1,NULL,MARIT,(void *)i);
pthread_create(&tid2,NULL,MQUAD,(void *)i);
pthread_create(&tid3,NULL,SCUB,(void *)i);
//Ici on attend la fin d'execution des 3 thread pour pouvoir terminer le programme
pthread_join(tid1,NULL);
pthread_join(tid2,NULL);
pthread_join(tid3,NULL);
return 0;
fclose(resultat);
}