Untitled


SUBMITTED BY: itsDaveLad

DATE: March 10, 2016, 3:23 p.m.

FORMAT: Text only

SIZE: 1.2 kB

HITS: 407

  1. #include "stdafx.h"
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <iostream>
  4. #include <cstring>
  5. using namespace std;
  6. char * newstr(char * temp){
  7. int i = 0, j = 0, N;
  8. N = strlen(temp) + 1;
  9. char *str = new char[N];
  10. strcpy(str, temp);
  11. char* fin_string = new char[N];
  12. while (i != N)
  13. {
  14. if (str[i] != '<')
  15. {
  16. fin_string[j] = str[i];
  17. i++;
  18. j++;
  19. }
  20. else
  21. {
  22. fin_string[j] = str[i];
  23. i++;
  24. j++;
  25. while (str[i] != '>')
  26. i++;
  27. fin_string[j] = str[i];
  28. i++;
  29. j++;
  30. }
  31. }
  32. return fin_string;
  33. delete[]str;
  34. }
  35. int main() {
  36. if (strcmp(newstr("Viktoria"), "Victoria") || strcmp(newstr(""), "") || strcmp(newstr("<kuku>"), "<>") || strcmp(newstr("<<h>>"), "<<>>")) {
  37. cout << "bad" << endl;
  38. return 1;
  39. }
  40. cout << "Input string" << endl;
  41. char * temp = new char[256];
  42. gets(temp);
  43. char * fin_string = newstr(temp);
  44. cout << "Well done, fine human. Your new string is down here: " << endl << fin_string << endl;
  45. delete[]fin_string;
  46. return 0;
  47. }

comments powered by Disqus