Advertisement
Guest User

Untitled

a guest
Mar 8th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 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;
  29.  
  30. cin.getline(input_str, 99);
  31.  
  32. StringParser parser(input_str,"/,\\");
  33.  
  34. while(parser.more())
  35. {
  36. p = parser.get(in);
  37. cout << p << endl;
  38. delete [] p;
  39. }
  40. system ("pause");
  41. return 0;
  42. }
  43.  
  44. //-------------------------------------
  45.  
  46. char *StringParser::get(char *str)
  47. {
  48. int j = 0;
  49. char *new_str;
  50. new_str = new char[100];
  51.  
  52. while(strchr(delimiters, input_str[pos]))
  53. pos++;
  54.  
  55. while(input_str[pos] != '\0' && !strchr(delimiters, input_str[pos]))
  56. if(j<100)
  57. new_str[j++] = input_str[pos++];
  58.  
  59. new_str[j] = '\0';
  60. return new_str;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement