fork download
  1. #include <iostream>
  2. #include <cstdlib>
  3. #include <cstdio>
  4. #include <limits.h>
  5.  
  6. using namespace std;
  7. char *getline()
  8. {
  9. char c;
  10. size_t bc=0;
  11. size_t bufsiz=PIPE_BUF;
  12. char *b = (char*)malloc(bufsiz);
  13. for(register unsigned i=0;(c=getc(stdin))!='\n';i++,bc++){
  14. if (i==bufsiz){
  15. char *b_n=(char*)realloc(b, bufsiz*=2);
  16. if (!b_n){perror("realloc fail!");}
  17. b=b_n;
  18. }
  19. b[i] = c;
  20. }
  21. b[bc]='\0';
  22. return b;
  23. }
  24. int main() {
  25. cout << "Who you might be?" <<endl;
  26. char *nmae=getline();
  27. cout << "Hello " << nmae << "!" <<endl;
  28. delete nmae;
  29. return 0;
  30. }
Success #stdin #stdout 0s 3432KB
stdin
Dolly

Desho?
stdout
Who you might be?
Hello Dolly!