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