Advertisement
Guest User

123

a guest
Oct 19th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <cstdio>
  4. #include <string.h>
  5.  
  6. using namespace std;
  7.  
  8. char* change_of_string(char string1[])
  9. {
  10.  
  11.     char result[300] = { "" };
  12.     int counter = 0;
  13.     int n;
  14.     for (int i = 0; i < strlen(string1); i++)
  15.     {
  16.         counter = 0;
  17.         char numbers[20] = { "" };
  18.         while (isdigit((int)string1[i]))
  19.         {
  20.             numbers[counter] = string1[i];
  21.             counter++;
  22.             i++;
  23.         }
  24.  
  25.         if (counter > 0)
  26.         {
  27.             i--;
  28.             n = atoi(numbers);
  29.             _itoa(n, numbers, 16);
  30.             strcat(result, "0x");
  31.             strcat(result, numbers);
  32.         }
  33.         else
  34.             strncat(result, &string1[i], 1);
  35.     }
  36.  
  37.     return result;
  38. }
  39.  
  40. void assertion(string test, char string1[])
  41. {
  42.     char result[100];
  43.     strcpy(result, change_of_string(string1));
  44.  
  45.     if (result == test)
  46.         cout << "ok" << endl;
  47.     else
  48.         cout << "no" << endl;
  49. }
  50. int main()
  51. {
  52.     assertion("as0x11df0x50", "as17df80");
  53.     assertion("0x18sdadsf0x123df", "24sdadsf291df");
  54.     assertion("0x6ae2b7e4", "1793243108");
  55.     assertion("asdfkjhgfuytewryfdsdffg", "asdfkjhgfuytewryfdsdffg");
  56.     assertion("", "");
  57.     system("pause");
  58.     return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement