Guest User

Untitled

a guest
Mar 8th, 2015
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. using namespace std;
  5.  
  6. class StringParser
  7. {
  8. private:
  9. int pos;
  10. char *input_str;
  11. char *delimiters;
  12. public:
  13. StringParser(char *inp, char *delim)
  14. {input_str = inp;delimiters = delim;pos = 0;}
  15. StringParser(char *delim)
  16. {delimiters = delim;pos = 0;}
  17. char *get(char *str);
  18. int get_int();
  19. double get_dbl();
  20. int more() {return input_str[pos] !='\0';}
  21. void reset() {pos = 0;}
  22. };
  23.  
  24. int main()
  25. {
  26. char input_str[100];
  27. char *p;
  28. char in[100];
  29.  
  30. cin.getline(input_str, 99);
  31. cin.getline(in, 99);
  32.  
  33. StringParser parser(input_str,"/,\\");
  34.  
  35. while(parser.more())
  36. {
  37. p = parser.get(in);
  38. cout << p << endl;
  39. delete [] p;
  40. }
  41. system ("pause");
  42. return 0;
  43. }
  44.  
  45. //-------------------------------------
  46.  
  47. char *StringParser::get(char *str)
  48. {
  49. int j = 0;
  50. char *new_str;
  51. new_str = new char[100];
  52. strcat(input_str, str);
  53.  
  54. while(strchr(delimiters, input_str[pos]))
  55. pos++;
  56.  
  57. while(input_str[pos] != '\0' && !strchr(delimiters, input_str[pos]))
  58. if(j<100)
  59. new_str[j++] = input_str[pos++];
  60.  
  61. new_str[j] = '\0';
  62. return new_str;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment