brich744
asked on
Error: Bad Ptr
Hello Everyone,
I am writing a program that lets a user enter in a equation and then tell if the program encounters an operator. What I am having a problem with is I am getting a Bad Ptr a run time error from the following pointer tokenPtr. When I debug the error is coming from this line
if(*tokenPtr == '(' || *tokenPtr == ')' || *tokenPtr == '+' || *tokenPtr=='-')
Also, the first variable is in the equation is being skipped by the 'if' evaluation.
(BTW: There is an expected space between each character)
I am writing a program that lets a user enter in a equation and then tell if the program encounters an operator. What I am having a problem with is I am getting a Bad Ptr a run time error from the following pointer tokenPtr. When I debug the error is coming from this line
if(*tokenPtr == '(' || *tokenPtr == ')' || *tokenPtr == '+' || *tokenPtr=='-')
Also, the first variable is in the equation is being skipped by the 'if' evaluation.
(BTW: There is an expected space between each character)
#include<iostream>
#include<string>
#include<cstring>
#include<sstream>
#include<iterator>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
char equation[20];
char* tokenPtr;
cout<<"Please Enter In A Equation"<<endl;
cin.getline(equation, '\n');
tokenPtr = strtok(equation," ");
while( tokenPtr != NULL)
{
cout<<tokenPtr<<endl;
tokenPtr = strtok(NULL, " ");
if(*tokenPtr == '(' || *tokenPtr == ')' || *tokenPtr == '+' || *tokenPtr=='-')
{
cout<<"This Is A Operator"<<endl;
}
}
system("PAUSE");
return 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
mccarl, sorry for repeating.
Sara
Sara
Sara