fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int main(void) {
  5. FILE *p;
  6. char *str;
  7. int lineno = 0;
  8.  
  9. p = stdin;
  10. str = malloc(100);
  11. if (!str) {
  12. fprintf(stderr, "no memory\n");
  13. exit(EXIT_FAILURE);
  14. }
  15. while (fgets(str, 100, p) != NULL) {
  16. printf("%d ==> str: %s", ++lineno, str); /* \n is already part of str */
  17. }
  18. free(str);
  19. return 0;
  20. }
Success #stdin #stdout 0.01s 1812KB
stdin
V. Guimaraes|Rio Ave|15|2|2012|2|0|
Academica|Benfica|25|3|2012|2|0|
stdout
1 ==> str: V. Guimaraes|Rio Ave|15|2|2012|2|0|
2 ==> str: Academica|Benfica|25|3|2012|2|0|