Guest User

Untitled

a guest
Jul 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <cctype>
  3. #include <cstring>
  4. #include <cstdlib>
  5. #include <string>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11. char string[] = "-4x^0 + x^1 + 4x^3 - 3x^4";
  12. int length = strlen(string);
  13. char copy[length];
  14. strcpy(copy, string);
  15. char *p = strtok(string, " +-");
  16. char *search;
  17. int counter = 0;
  18. while (p)
  19. {
  20. search = strstr(p, "x^");
  21. cout << "Token: " << p << endl;
  22. cout << "Search " << search << endl;
  23. p = strtok(NULL, " +-");
  24. counter++;
  25. }
  26.  
  27. cout << copy << endl;
  28. cout << "counter " << counter << endl;
  29. int *coefficient;
  30. coefficient = new int[counter];
  31.  
  32. p = strtok(copy, " +-");
  33. int a;
  34. while (p)
  35. {
  36. if (isdigit(p[0]))
  37. {
  38. cout << p[0] << " is a digit" << endl;
  39. char c = p[0];
  40. int b = c - 0;
  41. coefficient[a] = ;
  42. }
  43. p = strtok(NULL, " +-");
  44. a++;
  45. }
  46.  
  47. for (int i = 0; i < counter; i++)
  48. cout << coefficient[i] << endl;
  49. return 0;
  50. }
Add Comment
Please, Sign In to add comment