All pastes #258671 Raw Edit

Trucs

public c v1 · immutable
#258671 ·published 2006-11-26 19:31 UTC
rendered paste body
#include "get_next_line.h"void    my_putchar(char c){  write(1, &c, 1);}char    *tab_to_tab(char *tab1, char *tab2){  int   i;  int   j;  char  *tab3;  int   total_size;  int   taille1;  int   taille2;  i = my_strlen(tab1);  j = my_strlen(tab2);  total_size = 0;  taille1 = 0;  taille2 = 0;  tab3 = (char *)malloc(sizeof(tab3) * (i + j) + 1);  while (taille1 < i)    tab3[total_size++] = tab1[taille1++];  while(taille2 < j)    tab3[total_size++] = tab2[taille2++];  tab3[total_size] = '\0';  return (tab3);}char    *my_strcpy(char *dest, char *src){  int   taille;  taille = 0;  while (src[taille] != '\0')    {      dest[taille] = src[taille];      taille++;    }  dest[taille] = src[taille];  return (dest);}char                    *get_next_line(const int fd){  static        char    *result;  static        char    *stock;  static        int     i;  static        int     temp;  static        char    *a;  static        char    *suite;  static  int                   taille;  int                   j;  i = 0;  j = 0;  taille = TAILLE_READ - i;   if ((stock = (char*)malloc(sizeof(stock) * TAILLE_BUFF)) == NULL)    aff_err(4);  if ((result = (char*)malloc(sizeof(result) * TAILLE_BUFF + i + 1)) == NULL)    aff_err(4);  if ((a = (char*)malloc(sizeof(a) * TAILLE_BUFF + i + 1)) == NULL)    aff_err(4);  if ((suite = (char*)malloc(sizeof(suite) * taille)) == NULL)    aff_err(4);  if ((temp = read(fd, a, TAILLE_READ)) == 0)    return (0);  while (a[i] != '\n' && a[i])    {      stock[i] = a[i];      if (temp == -1)        aff_err(3);      i++;    }  taille = TAILLE_READ - i;  while (i < taille && suite[j] != '\n' && a[i] != '\n')    {      suite[j] = a[i];      j++;      taille--;    }  suite[j] = '\0';  stock[i] = '\0';  my_strcpy(result, tab_to_tab(stock, suite));  free(stock);  return (result);}/* LE GET_NEXT_LINE.H */#ifndef __GET_NEXT_LINE_H__#define __GET_NEXT_LINE_H__#define TAILLE_READ 5#define TAILLE_BUFF 1000#include <unistd.h>#include <stdlib.h>#include <stdio.h>#define ERROR_OPEN 1#define ERROR_LSEEK 2#define ERROR_READ 3#define ERROR_MALLOC 4int     my_strlen(char *str);void    aff_err(int type);char    *get_next_line(const int fd);char    *my_strcpy(char *dest, char *src);int      my_putstr(char *str);#endif /* __GET_NEXT_LINE_H__ *//* LE FICHIER TEST A FOUTRE EN STDIN */(Pcboy@crime 218)cat testsaluto ca va ?ok pas de probleme.ca marche plutot correctement.