Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #define lengthMAX 1000
  4.  
  5. int foo(char*,char*,int*);
  6.  
  7. int main() {
  8.     int size = 0;
  9.     char* string = (char*)malloc(lengthMAX * sizeof(char));
  10.     gets_s(string, lengthMAX);
  11.     char* new_string = (char*)malloc(lengthMAX * sizeof(char));
  12.     int* new_array = (int*)malloc(lengthMAX * sizeof(int));
  13.     size = foo(string, new_string, new_array);
  14.     puts(new_string);
  15.  
  16.     for (int i = 0; i < size; ++i) {
  17.         printf("%d ", new_array[i]);
  18.     }
  19.     system("pause");
  20. }
  21.  
  22. int foo(char* string,char* new_string,int* new_array) {
  23.     int size_of_array = 0;
  24.     for (int i = 0; i < lengthMAX; ++i) {
  25.         if (string[i] <= '9' && string[i] >= '0') {
  26.             *new_array = (int)(string[i] - '0');
  27.             ++new_array;
  28.             ++size_of_array;
  29.         }
  30.         else {
  31.             *new_string = string[i];
  32.             ++new_string;
  33.         }
  34.     }
  35.     *new_string = '/0';
  36.     return size_of_array;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement