Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 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. result[index++] = strtoll(temp_ptr, &temp_ptr, 10);
  24. }
  25. ++temp_ptr;
  26. }
  27. return result;
  28. }
  29. int main()
  30. {
  31. char* text = new char[255];
  32. cout << "Enter text: ";
  33. cin.getline(text, 50);
  34. int *res = onlyNumbers(text);
  35.  
  36. for (int i = 1; i <= *res; ++i)
  37. {
  38. cout << res[i]*10 << " ";
  39. }
  40. cout << endl;
  41.  
  42. system("pause");
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement