fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4.  
  5. char *getNum(FILE *f)
  6. {
  7. char* num;
  8. int count;
  9. int c;
  10.  
  11. num=malloc(1);
  12. count=0;
  13. while(isdigit(c=fgetc(f)))
  14. {
  15. num[count]=c;
  16. num=realloc(num,++count);
  17. }
  18. num[count]=0;
  19. return num;
  20. }
  21.  
  22. int main(int argc, char* argv[])
  23. {
  24. FILE *in;
  25. char** n;
  26. int count;
  27. int i;
  28.  
  29. //if (argc!=2) exit(2);
  30. //in=fopen(argv[1],"r");
  31. //if (!in) exit(3);
  32. in=stdin;
  33.  
  34. n=NULL;
  35. count=0;
  36. while(!feof(in))
  37. {
  38. n=realloc(n,(count+1)*sizeof(char*));
  39. n[count++]=getNum(in);
  40. }
  41. for(i=0;i<count;++i)
  42. {
  43. printf ("%s\n",n[i]);
  44. }
  45. free(n);
  46. return 0;
  47. }
Success #stdin #stdout 0s 1924KB
stdin
123456789
234567890
345678901
stdout
123456789
234567890
345678901