Guest User

Untitled

a guest
Dec 10th, 2019
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int k = 0;
  9. char charTemp;
  10. char* charBuffer;
  11. char* charBufferNew = NULL;
  12.  
  13. while (true)
  14. {
  15. charTemp = getchar();
  16. if (charTemp == '\n') break;
  17.  
  18. k++;
  19. charBuffer = (char*)realloc(charBufferNew, k);
  20. if (charBuffer != NULL) {
  21. charBufferNew = charBuffer;
  22. charBufferNew[k - 1] = charTemp;
  23. //free(charBuffer);
  24. }
  25. else {
  26. free(charBufferNew);
  27. cout << "Memory reallocation error!\n";
  28. }
  29. }
  30.  
  31. // We're separating value on chunks
  32. int* chunk = new int[k / 8];
  33. int j = 0;
  34. int d = 0;
  35. int nChunks = 0;
  36. charBuffer = new char[k];
  37. while (true)
  38. {
  39. charBuffer[d] = charBufferNew[j];
  40. j++;
  41. d++;
  42. if (d == 8)
  43. {
  44. chunk[nChunks] = atoi(charBuffer);
  45. cout << "Chunk[i + 1] - " << chunk[nChunks] << endl;
  46. nChunks++;
  47. d = 0;
  48. if (j >= k) break;
  49. }
  50. }
  51. cout << nChunks << " Chunks\n";
  52.  
  53. delete[] charBuffer;
  54. charBuffer = new char[k];
  55. // 10000000120000000
  56. for (int i = nChunks; i > 0; i--) {
  57. char* intBuffer = new char[9];
  58. chunk[i] /= 2.0;
  59. for (int i = 0; i < nChunks; i++) {
  60. int m = 10;
  61. for (int j = 0; j <= 8; j++) {
  62. intBuffer[j] = chunk[i] % m;
  63. m *= 10;
  64. //cout << m << endl;
  65. cout << intBuffer[i] << '\n';
  66. }
  67.  
  68. // 5231
  69. }
  70. cout << intBuffer;
  71. system("pause");
  72. return 0;
  73. //strcat(intBuffer, charBuffer, 10);
  74. }
  75. cout << charBuffer << endl;
  76.  
  77. system("pause");
  78. delete[] charBuffer;
  79. free(charBufferNew);
  80. }
RAW Paste Data