fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. //tirei os comentários porque eles davam indicações erradas mesmo
  6. //o erro de runtime é provocado propositalmente pelo código através da função exit
  7. void vazio(void) {
  8. char *str = malloc(1);
  9. char c;
  10. int i = 0;
  11. printf("Informe a string: ");
  12. do {
  13. c = getc(stdin);
  14. if (c != '\n') {
  15. str = realloc(str, i + 1);
  16. str[i++] = c;
  17. }
  18. } while (c != '\n');
  19. str[i] = '\0';
  20. if(strlen(str) == 0 || strcmp(str, "0") == 0) {
  21. printf("\7\a\nErro!\n");
  22. exit(EXIT_FAILURE);
  23. }
  24. printf("\nString: %s", str);
  25. free(str);
  26. }
  27.  
  28. int main(void) {
  29. vazio();
  30. }
  31.  
  32. //https://pt.stackoverflow.com/q/48119/101
Runtime error #stdin #stdout 0s 9424KB
stdin
stdout
Informe a string: 
Erro!