help pointeur please - C++ - Programmation
Marsh Posté le 11-12-2002 à 13:24:55
Et ta fonction more_line on peut la voir. A mon avis ca vient de la... si str est pas egal a NULL (a 0 quoi...) elle doit faire un truc qui doit planter... Nan ?
Marsh Posté le 11-12-2002 à 15:32:07
oki dsl voila tt : 
 
void *malloc(unsigned int size); 
 
#include <fcntl.h> 
#define BUFF_SIZE 42 
 
 
static char buff[BUFF_SIZE]; 
static int count = 0; 
static int Rbuf = 0; 
//static int start; 
static int Cread = 0; 
 
static char *more_line(char *line,int cur) 
{ 
  char *str; 
  int len; 
 
  str = malloc((len =(line ? my_strlen(line) : 0)) + cur + 1); 
  my_strcpy(str,line ? line : "" ); 
  my_strncpy(str + len, buff + count, cur); 
  str[len + cur] = 0; 
  if (line) 
    free(line); 
  count += cur + 1; 
  return (str); 
 
} 
 
static int read_f(int fd) 
{ 
  Rbuf = read(fd, buff, BUFF_SIZE); 
  count = 0; 
  if (Rbuf != BUFF_SIZE) 
    Cread = Rbuf; 
} 
 
char *get_next_line(const int fd) 
{ 
  int tmp; 
  char *str; 
 
  for (str = 0tmp = 0; ; tmp++) 
    { 
      if (count >= Rbuf) 
 { 
   if (Cread) 
     return (0); 
   read_f(fd); 
   tmp = 0; 
 } 
      if (buff[count + tmp] == '\n' 
 
 { 
   str = more_line(str, tmp); 
   return (str); 
 } 
      if (count + tmp == Rbuf - 1) 
 str = more_line(str, tmp + 1); 
    } 
} 
 
//char	*get_next_line(const int fd); 
 
int	main() 
{ 
  char	*s; 
  int	fd; 
 
  fd = open ("test", O_RDONLY); 
  //s =  get_next_line(fd); 
  while ((s = get_next_line(0))) 
    { 
    my_putstr(s); 
      close (fd); 
      free(s); 
  } 
  return (0); 
}
Marsh Posté le 11-12-2002 à 15:37:48
bah voila, si line != 0 ton (line ? my_strlen(line) : 0) doit chier un peu, nan ?
Marsh Posté le 11-12-2002 à 20:25:22
| Code : 
 | 
Marsh Posté le 12-12-2002 à 02:31:34
Cas grave, procédure d'urgence... 
The seven secrets of successful programmers 
How To Write Unmaintainable Code 
Comment Poser Les Questions De Manière Intelligente 
How to Report Bugs Effectively 
I need help with my homework! 
Recommended C Style and Coding Standards. 
The Ten Commandments for C Programmers (Annotated Edition) 
 
C++ FAQ LITE Française 
FAQ C fr.comp.lang.c Française. 
 
Pourquoi voudrait-on déboguer un pavé mal indenté, sans commentaire, aux noms cryptiques et même pas copié/collé correctement ? 
Zut à la fin ! 
 
Il y a eu livraison de boolays aujourd'hui ou quoi ?
Marsh Posté le 11-12-2002 à 12:28:40
voila si vous regarder les deux lignes en gras, ce qui se passe logiquement c que l;adreee du pointeur devient 0, donc c n'importe qoi pour moi! met sans faire str = 0 ca marche pas donc qq1 pourrais t'il mexpliquer?? pk ca?
 
 
merci.
int tmp;
char *str;
for (str = 0, tmp = 0; ; tmp++)
{
if (count >= Rbuf)
{
if (Cread)
return (0);
read_f(fd);
tmp = 0;
}
if (buff[count + tmp] == '\n'
{
str = more_line(str, tmp);
return (str);
}
if (count + tmp == Rbuf - 1)
str = more_line(str, tmp + 1);
}