fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(int argc, char *argv[])
  6. {
  7. int len1=0;
  8. FILE* p = stdin;
  9. char a;
  10. char b[10+1]; // <<== need one more byte for the terminator
  11. //p = fopen(argv[1],"r");
  12. while (len1 < 10) // <<== avoid buffer overruns
  13. {
  14. a = fgetc(p);
  15.  
  16. if(a == ' ') break;
  17. else
  18. {
  19. len1++;
  20. b[len1-1] = a;
  21. }
  22. }
  23. b[len1] = '\0'; // <<== Don't forget to zero-terminate
  24. printf("%s\n", b); // <<== Pass the buffer, not the last character from it
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0.02s 1724KB
stdin
hahahalkasjdl
stdout
hahahalkas