hi,
i have a program which read the input stream as a character then it transdforms this charcters to integers

in the input stream there is ^, ex , x^2
how can i deal with.

Recommended Answers

All 3 Replies

another Question:

when i use atoi(char) , there is an error

in the follwing program i'm trying to read a characters and transform them to integers .
the input will be in this form x^y
but i become an error


char x,y,z;
int i,k,res;

cin>>x>>y>>z;

if( isdigit(x))
i= atoi(x);

if(isdigit(z))
k= atoi(z);

if(y=='^')
res= pow(i,k);

cout<<"res="<<res;

that is because the function atoi isn't for converting a char to an int, it converts a string (char array) to an int. If you want to convert a char to an int you need to type cast. for example:

char a = 'z';
int num = (int) a;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.