Advertisement
FiddleComputers

input_string

Oct 27th, 2020
1,009
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.30 KB | None | 0 0
  1. char* input_string()
  2. {
  3.     // getchar(); //on vide le buffer, cette ligne est optionnelle
  4.  
  5.     int n = 0;
  6.     char *c = (char*) malloc(1);
  7.     char saisie = getchar();
  8.     while(saisie != '\n')
  9.     {
  10.         c[n] = saisie;
  11.         saisie = getchar();
  12.         n++;
  13.         c = (char*) realloc(c, n+1);
  14.     }
  15.  
  16.     c[n] = '\0';
  17.  
  18.     return c;
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement