Mathc complexes/Fichiers c : fp mz
Apparence
Le code de la fonction :
/* ------------------------------------ */
/* ------------------------------------ */
double **fp_mZ(
double **A,
char FileName[],
char MatrixName[],
int Sr,
int Pr,
int Si,
int Pi,
int Cn
)
{
FILE * fp = fopen(FileName,"a");
int r;
int c;
int n_c;
int n_c_LAST;
int n_c_FIRST;
fprintf(fp,"%s",MatrixName);
n_c = R1;
while(n_c<A[C_SIZE][C0])
{
n_c+=Cn*C2;
n_c_FIRST = n_c-Cn*C2;
if(n_c<A[C_SIZE][C0])n_c_LAST = n_c;
else n_c_LAST = A[C_SIZE][C0];
for(r=R1; r<A[R_SIZE][C0]; r++)
{
fprintf(fp,"\n");
for (c=n_c_FIRST; c<n_c_LAST; c+=C2)
fprintf(fp,"%+*.*f%+*.*fi ",Sr,Pr,A[r][c],Si,Pi,A[r][c+C1]);
}
fprintf(fp,"\n");
}
fprintf(fp,"\n");
fclose(fp);
return(A);
}
/* ------------------------------------ */
/* ------------------------------------ */
La fonction fp_mZ(); est identique à la fonction p_mZ(); mais elle écrit les nombres dans un fichier texte.
Il faut utiliser la fonction fprintf(fp,..); ou fp est un pointeur sur un fichier texte
FILE * fp = fopen(FileName,"a");
Il faut fermer ce fichier texte en fin de fonction
fclose(fp);
Installer et compiler ce fichier dans votre répertoire de travail.
c00a.c |
|---|
/* ------------------------------------ */
/* Save as : c00a.c */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
void fun(int r,int c)
{
double **A = i_mZ(r,c);
clrscrn();
printf(" See the file \n\n");
fp_mZ(A,"a.txt"," A :", S9,P2, S7,P2,C6);
f_mZ(A);
}
/* ------------------------------------ */
int main(void)
{
time_t t;
srand(time(&t));
do
fun(rp_I(R4),rp_I(C5));
while(stop_w());
return 0;
}
/* ------------------------------------ */
/* ------------------------------------ */