fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4.  
  5.  
  6. int db_char_malloc(int x, int y)
  7. {
  8. int i;
  9.  
  10. i = 0;
  11. char **db_char = (char **)malloc(y * sizeof(char *));
  12. while (i<y)
  13. {
  14. db_char[i] = (char *)malloc(x * sizeof(char));
  15. i++;
  16. }
  17. return (db_char);
  18. }
  19.  
  20. int db_int_malloc(int y)
  21. {
  22. int *db_int = (int *)malloc(y * sizeof(int));
  23. return (db_int);
  24. }
  25.  
  26. int count_elems(char *str)
  27. {
  28. int count;
  29. int i;
  30.  
  31. count = 0;
  32. i = 0;
  33. while(str[i] != '\0')
  34. {
  35. if (str[i] <= '9' && str[i] >= '0')
  36. {
  37. while (str[i] <= '9' && str[i] >= '0')
  38. i++;
  39. count++;
  40. }
  41. else if (str[i] == ' ')
  42. i++;
  43. else
  44. {
  45. count++;
  46. i++;
  47. }
  48. }
  49. return (count);
  50. }
  51.  
  52. #include <unistd.h>
  53.  
  54.  
  55. char main()
  56. {
  57. int i;
  58. int j;
  59. int count_elem;
  60. int i_v_str;
  61. char str[] = "1 + 2 * ((34 - 4 * 3))";
  62. i = 0;
  63. j = 0;
  64. i_v_str = 0;
  65. count_elem = count_elems(str);
  66. char **db_char = db_char_malloc(10, count_elem);
  67. int *db_int = db_int_malloc(count_elem);
  68. while (str[i_v_str] != '\0')
  69. {
  70. i = 0;
  71. if (str[i_v_str] <= '9' && str[i_v_str] >= '0')
  72. {
  73. while (str[i_v_str] <= '9' && str[i_v_str] >= '0')
  74. {
  75. db_char[j][i] = str[i_v_str];
  76. i++;
  77. i_v_str++;
  78. }
  79. db_char[j][i] = '\0';
  80. j++;
  81. }
  82. else if (str[i_v_str] == ' ')
  83. i_v_str++;
  84. else
  85. {
  86. db_char[j][i] = str[i_v_str];
  87. i++;
  88. db_char[j][i] = '\0';
  89. i_v_str++;
  90. j++;
  91. }
  92. }
  93. j = 0;
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100. return(db_char);
  101. }
Runtime error #stdin #stdout 0s 9424KB
stdin
Standard input is empty
stdout
Standard output is empty