Advertisement
oaktree

Untitled

Nov 13th, 2016
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.45 KB | None | 0 0
  1. #include <string.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. int main(void) {
  6.  
  7.     char* s = NULL;
  8.     size_t s_len = 0;
  9.  
  10. /* Start taking input, dynamically. */
  11.    
  12.     printf("Input a string...\n");
  13.  
  14.     do {
  15.  
  16.         s = realloc( s , ++s_len * sizeof(char) );
  17.  
  18.     } while ( ( s[ s_len - 1 ] = getchar() ) != '\n' );
  19.  
  20.     s[--s_len] = 0x00;
  21.  
  22. /* End dynamic input procedure. */
  23.  
  24.     printf("\n%s\n", s);
  25.     printf("s_len = %i\n", (int)s_len);
  26.  
  27.     free(s);
  28.  
  29.     return 0;
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement