help pointeur please

help pointeur please - C++ - Programmation

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);
    }

Reply

Marsh Posté le 11-12-2002 à 12:28:40   

Reply

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 ?


---------------
Ce n'est point ma façon de penser qui a fait mon malheur, c'est celle des autres.
Reply

Marsh Posté le 11-12-2002 à 14:25:06    

Erf, difficile de suivre avec une indentation pourrie !

Reply

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);
}

Reply

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 ?


---------------
Ce n'est point ma façon de penser qui a fait mon malheur, c'est celle des autres.
Reply

Marsh Posté le 11-12-2002 à 16:40:29    

:pt1cable:


---------------
du bon usage de rand [C] / [C++]
Reply

Marsh Posté le 11-12-2002 à 20:25:22    

Code :
  1. void *malloc(unsigned int size);
  2. #include <fcntl.h>
  3. #define BUFF_SIZE 42
  4. static char buff[BUFF_SIZE];
  5. static int count = 0;
  6. static int Rbuf = 0;
  7. //static int start;
  8. static int Cread = 0;
  9. static char *more_line(char *line,int cur)
  10. {
  11.   char *str;
  12.   int len;
  13.   str = malloc((len =(line ? my_strlen(line) : 0)) + cur + 1);
  14.   my_strcpy(str,line ? line : "" );
  15.   my_strncpy(str + len, buff + count, cur);
  16.   str[len + cur] = 0;
  17.   if (line)
  18.     free(line);
  19.   count += cur + 1;
  20.   return (str);
  21. }
  22. static int read_f(int fd)
  23. {
  24.   Rbuf = read(fd, buff, BUFF_SIZE);
  25.   count = 0;
  26.   if (Rbuf != BUFF_SIZE)
  27.     Cread = Rbuf;
  28. }
  29. char *get_next_line(const int fd)
  30. {
  31.   int tmp;
  32.   char *str;
  33.   for (str = 0tmp = 0; ; tmp++)
  34.     {
  35.       if (count >= Rbuf)
  36. {
  37.   if (Cread)
  38.     return (0);
  39.   read_f(fd);
  40.   tmp = 0;
  41. }
  42.       if (buff[count + tmp] == '\n')
  43. {
  44.   str = more_line(str, tmp);
  45.   return (str);
  46. }
  47.       if (count + tmp == Rbuf - 1)
  48. str = more_line(str, tmp + 1);
  49.     }
  50. }
  51. //char *get_next_line(const int fd);
  52. int main()
  53. {
  54.   char *s;
  55.   int fd;
  56.   fd = open ("test", O_RDONLY);
  57.   //s =  get_next_line(fd);
  58.   while ((s = get_next_line(0)))
  59.     {
  60.     my_putstr(s);
  61.       close (fd);
  62.       free(s);
  63.   }
  64.   return (0);
  65. }


---------------
voxel terrain render engine | animation mentor
Reply

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 ?


---------------
Bricocheap: Montage de ventilo sur paté de mastic silicone
Reply

Sujets relatifs:

Leave a Replay

Make sure you enter the(*)required information where indicate.HTML code is not allowed