Fichier

laroui_nesrine Messages postés 1 Date d'inscription   Statut Membre Dernière intervention   -  
fiddy Messages postés 11069 Date d'inscription   Statut Contributeur Dernière intervention   -
slt j'ai déja un pgm en c dans le code blocks qui marche sans errreurs
mais quand je faire l'exécution de ce pgm dans linux (il donne une erreurs dans la déclaration du fichier
et je ne peus pas corrigé cette erreurs
le code:
void fichieresult(int a, float b)
{
FILE *fichier;
int i;
fichier = fopen("D:\\fichier.txt", "a++");
fprintf(fichier, "%d,%f\n", a, b);
fclose(fichier);
}
int main()
{
float sommep1=0,sommep2=0,sommep3=0,L;
float min,timex[M][3];
int t[M][M];
int j,i=0,larg,h,nb_tot,k,l,Imin;


srand(time(NULL));
nb_tot=0;
h=(rand()%5)+2;
for(i=0; i<h; i++)
{ larg=(rand()%5)+2;
printf("le nb_max_t pour le niveau larg%d =%d\n",i,larg);
nb_tot=nb_tot+larg; }
printf("le nbr total des taches =%d\n\n\n",nb_tot);

/***************************REMPLIIR LA MATRICE DES ARC*********************************/
srand(time(NULL));
for (i=0;i<nb_tot;i++)
{ t[i][0]=0;
for (j=1;j<nb_tot;j++)
if(i==j)t[i][j]=0;else t[i][j]=rand()%2; }

for (i=0;i<nb_tot;i++)
{for (j=1;j<nb_tot;j++)
{if((t[i][j]==1)&&(t[i+1][j]==1))
t[i][i+1]=0;}
}

srand(time(NULL));
for (k=0;k<nb_tot;k++)
{ for (l=0;l<3;l++)
timex[k][l]=(rand()%10)+3;
}
/**************************************** la boucle******************************************/
for (k=0;k<nb_tot;k++)
{ min=timex[k][0];
Imin=0;
for (l=1;l<3;l++)
if (min>timex[k][l])
{Imin=l;
min=timex[k][l];
}
i=0;
while(i<3){
if(Imin!=i)
{timex[k][i]=0;}
i++;
}
if(k<nb_tot)
{
j=0;
for(j=0;j<=k;j++)
{timex[k+1][0]=timex[k+1][0]+timex[j][0];
timex[k+1][1]=timex[k+1][1]+timex[j][1];
timex[k+1][2]=timex[k+1][2]+timex[j][2];}
}
j=0;
for(j=0;j<k;j++)
timex[j][Imin]=0;

}

for (k=0;k<nb_tot;k++)
sommep1=sommep1+timex[k][0];
printf("le temps d'execution du P1 est:%f\n\n",sommep1);
for (k=0;k<nb_tot;k++)
sommep2=sommep2+timex[k][1];
printf("le temps d'execution du P2 est:%f\n\n",sommep2);
for (k=0;k<nb_tot;k++)
sommep3=sommep3+timex[k][2];
printf("le temps d'execution du P3 est:%f\n\n",sommep3);

/********************le temps maximal pour l'execution des taches*************************/
L=sommep1;
if(sommep2>L)
L=sommep2;
{if(sommep3>L)
L=sommep3;}
printf("le temps total d'execution de %d taches est: %f\n",nb_tot,L);

fichieresult(nb_tot,L);

return 0;

}
A voir également:

1 réponse

fiddy Messages postés 11069 Date d'inscription   Statut Contributeur Dernière intervention   1 846
 
Bonjour,
fichier = fopen("D:\\fichier.txt", "a++");
a++ ??? C'est quoi ça ? Ca n'existe pas en mode pour fopen. Plutôt : a, a+, r, ...
srand(time(NULL));
A n'appeler qu'une seule fois...

Pour l'erreur, ça serait mieux que tu nous copie-colles l'erreur.
1