fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main(void)
  5. {
  6. char buffer[5];
  7.  
  8. if (fgets(buffer, sizeof(buffer), stdin) != NULL)
  9. printf("First : Length = %d, buffer[strlen(buffer) - 1] = '%c'\n", strlen(buffer), buffer[strlen(buffer) - 1]);
  10. while (fgetc(stdin) != '\n');
  11.  
  12. if (fgets(buffer, sizeof(buffer), stdin) != NULL)
  13. printf("Second: Length = %d, buffer[strlen(buffer) - 1] = '%c'\n", strlen(buffer), buffer[strlen(buffer) - 1]);
  14. while (fgetc(stdin) != '\n');
  15.  
  16. if (fgets(buffer, sizeof(buffer), stdin) != NULL)
  17. printf("Third : Length = %d, buffer[strlen(buffer) - 1] = '%c'\n", strlen(buffer), buffer[strlen(buffer) - 1]);
  18.  
  19. if (fgets(buffer, sizeof(buffer), stdin) != NULL)
  20. printf("Fourth: Length = %d, buffer[strlen(buffer) - 1] = '%c'\n", strlen(buffer), buffer[strlen(buffer) - 1]);
  21.  
  22. return 0;
  23. }
  24.  
Success #stdin #stdout 0s 2116KB
stdin
12345
1234
123
12
stdout
First : Length = 4, buffer[strlen(buffer) - 1] = '4'
Second: Length = 4, buffer[strlen(buffer) - 1] = '4'
Third : Length = 4, buffer[strlen(buffer) - 1] = '
'
Fourth: Length = 3, buffer[strlen(buffer) - 1] = '
'