fork(1) download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <ctype.h>
  4. #include <string.h>
  5.  
  6. void flush_buffer(void);
  7. void write_string(char string[], int n);
  8. void clean_buf_str(char string[]);
  9.  
  10. int main(void)
  11. {
  12. char buffer[80] = "";
  13. char ** pas;
  14. int length;
  15. printf("Сколько слов вы хотите ввести? ");
  16. scanf("%d", &length);
  17. flush_buffer();
  18. printf("Теперь введите %d слов:\n", length);
  19. pas = (char **) malloc(length * sizeof(char *));
  20. for (int i = 0; i < length; i++)
  21. {
  22. write_string(buffer, 80);
  23. pas[i] = (char *) malloc( (strlen(buffer) + 1) * sizeof(char *));
  24. strncpy(pas[i], buffer, 80);
  25. printf("%s\n", pas[i]);
  26. clean_buf_str(buffer);
  27. }
  28.  
  29. for (int j = 0; j < length; j++)
  30. free(pas[j]);
  31.  
  32. free(pas);
  33.  
  34. return 0;
  35. }
  36.  
  37.  
  38. void write_string(char string[], int n)
  39. {
  40. int i = 0;
  41. char ch;
  42. while ( (ch = getchar()) && i < n)
  43. {
  44. if (isspace(ch) || ispunct(ch))
  45. break;
  46. else
  47. {
  48. string[i] = ch;
  49. i++;
  50. }
  51. }
  52. }
  53.  
  54. void flush_buffer(void)
  55. {
  56. while (getchar() != '\n')
  57. continue;
  58. }
  59.  
  60. void clean_buf_str(char string[])
  61. {
  62. while (*string)
  63. {
  64. *string = '\0';
  65. string++;
  66. }
  67. }
  68.  
  69.  
Time limit exceeded #stdin #stdout 5s 4220KB
stdin
Standard input is empty
stdout
Standard output is empty