Aller au contenu

Mathc complexes/h08d

Un livre de Wikilivres.


Application

Le code de la fonction :

/* ------------------------------------ */
/* ------------------------------------ */
double **fPE_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,"%+*.*e,%+*.*e, ",Sr,Pr,A[r][c],Si,Pi,A[r][c+C1]);
          }
      fprintf(fp,"\n");
     }
fprintf(fp,"\n");

fclose(fp);

return(A);
}
/* ------------------------------------ */
/* ------------------------------------ */
La fonction fPE_mZ(); est identique à la fonction PE_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.

c00b.c
/* ------------------------------------ */
/*  Save as :   c00b.c                  */
/* ------------------------------------ */
#include "w_a.h"
/* ------------------------------------ */
void fun(int r,int c)
{
double **A     = i_mZ(r,c);

  clrscrn();

  printf(" See the file \n\n");
  
  fPE_mZ(A,"a.txt"," A :", S5,P1, S7,P1,C4);

  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;
}
/* ------------------------------------ */
/* ------------------------------------ */