Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. int* onlyNumbers(char* text)
  2. {
  3. char* temp_ptr = text;
  4. int count = 0;
  5. while(*temp_ptr)
  6. {
  7. if(isdigit(*temp_ptr))
  8. {
  9. while(isdigit(* ++temp_ptr)){}
  10. ++count;
  11. }
  12. if (*temp_ptr)
  13. ++temp_ptr;
  14. }
  15. int *result = new int[count + 1];
  16. result[0]= count;
  17. temp_ptr = text;
  18. int index = 1;
  19. while (index <= count)
  20. {
  21. if (isdigit(*temp_ptr))
  22. {//hjgf45365sdg
  23. int number = 0;
  24. while(isdigit(*temp_ptr))
  25. {
  26. number = number * 10 + (*temp_ptr - '0');
  27. ++temp_ptr;
  28. }
  29. result[index++] = number;
  30. }
  31. ++temp_ptr;
  32. }
  33. return result;
  34. }
  35. int main()
  36. {
  37. char* text = new char[255];
  38. cout << "Enter text: ";
  39. cin.getline(text, 50);
  40. int *res = onlyNumbers(text);
  41.  
  42. for (int i = 1; i <= *res; ++i)
  43. {
  44. cout << res[i]/2 << " ";
  45. }
  46. cout << endl;
  47.  
  48. system("pause");
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement