Advertisement
Guest User

Untitled

a guest
Dec 30th, 2011
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. int main(int ac,char** av){
  5. char* buf = 0;
  6. int capa = 0;
  7. int used = 0;
  8. for(;;){
  9. int c = getchar();
  10. if( c== -1 ) break;
  11. if( used +2 > capa ){
  12. capa = capa + 5;
  13. buf = (char*)realloc(buf,capa);
  14. if(buf==0){
  15. perror("メモリ不足");
  16. break;
  17. }
  18. }
  19. buf[used]=c;
  20. buf[used+1]=0;
  21. used ++;
  22. }
  23. if( buf != 0){
  24. printf("input is %s\n",buf);
  25. }
  26. return EXIT_SUCCESS;
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement