C/realloc

Pàgina inicial

Reply to this message
Autor: Patrick Dupre
Data:  
A: Guilde
Assumpte: C/realloc
Bonjour,

Voici un bout de code c.
Ce qui m'etonne c'est que la valeur du pointeur n'est jamais changee
(sauf apres ce premier appel)

#define NB_PAR 10
typedef double lineArray [NB_PAR] ;
typedef lineArray *floatMatrix ;

main () {
   unsigned long int nb_lines, i ;
   nb_lines = 0 ;
   floatMatrix lines = NULL ;
   for (i = 0 ; i < 5 ; i++) {
     lines = (floatMatrix) realloc (lines, (++nb_lines) * sizeof (lineArray)) ;
     printf ("Ptr new: %d\n", lines) ;
     }
   }



-- 
---
==========================================================================
  Patrick DUPRÉ                      |   |
  Department of Chemistry            |   |    Phone: (44)-(0)-1904-434384
  The University of York             |   |    Fax:   (44)-(0)-1904-432516
  Heslington                         |   |
  York YO10 5DD  United Kingdom      |   |    email: pd520@???
==========================================================================