Exemple #1
0
char	*get_next_line(const int fd)
{
  static char	buffer[BUFFER_SIZE + 1];
  static int	tmp = 0;
  int		n;
  char		*line;

  line = NULL;
  if (fd < 0)
    return (NULL);
  if (buffer[tmp++] == '\n')
    {
      line = strct(line, buffer, &tmp);
      if (buffer[tmp] == '\n')
	return (line);
    }
  while ((n = read(fd, buffer, BUFFER_SIZE)) > 0)
    {
      buffer[n] = '\0';
      tmp = 0;
      line = strct(line, buffer, &tmp);
      if (buffer[tmp] == '\n')
	return (line);
    }
  if (line != NULL && line[0] == 0)
      return (NULL);
  return (line);
}
int main()
{
	char s[15] = "Hello, ";
	char t[7] = "world!";
	printf("s = %s\n", s);
	printf("t = %s\n", t);
	strct(s, t);
	printf("s = %s\n", s);
	printf("t = %s\n", t);
}