| | |
how to convert char to integer???
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
Hi Blitzer,
I've compiled this with Dev-C++ and it worked correctly.
Good luck.
C++ Syntax (Toggle Plain Text)
#include <cstdlib> #include <iostream> using namespace std; int main() { char a_char[10]; cin >> a_char; cout << "As an integer: " << atoi(a_char); }
Good luck.
Well you can create a short string with
Then pass that to atoi, though strtol etc are better long term bets.
A quick answer is to do
C++ Syntax (Toggle Plain Text)
char s[2]; s[0] = ch; s[1] = '\0';
A quick answer is to do
C++ Syntax (Toggle Plain Text)
intVal = ch - '0';
•
•
Join Date: Jul 2006
Posts: 4
Reputation:
Solved Threads: 0
I have some ploblem
I want to make calculator for postfix number
example input : 45+
answer is 9
and I use
and this is my postfix fuction
I think main problem is "item" I have 45+ and I want to change it to 4 and 5 and then I use atoi to convert to interger
but I don't know how to change
help me please
I want to make calculator for postfix number
example input : 45+
answer is 9
and I use
C++ Syntax (Toggle Plain Text)
char* number = new char[20]; cin>>number; c.postfix(number); // use fuction postfix to convert
and this is my postfix fuction
C++ Syntax (Toggle Plain Text)
void Calculator:postfix(char* item){ // I don't know this is right?? int i1; for(int i=0;i<20;i++){ if(item[i]='+'){ i1 = atoi(item[i-1]); //<<< this is error T_T item[i]=item[i-2]+item[i-1]; top=top-2; i=i-2; stack[top] = item[i]; } else{ stack[top] = item[i]; top++; } } }
I think main problem is "item" I have 45+ and I want to change it to 4 and 5 and then I use atoi to convert to interger
but I don't know how to change
help me please
Last edited by Dave Sinkula; Jul 25th, 2006 at 8:07 pm.
Please post the code using [code] tags.
Hope it helped,
Bye.
char* number = new char[20];
cin>>number;
c.postfix(number); // use fuction postfix to convert
and this is my postfix fuction
void Calculator : Postfix(char* item)
{
// give variables meaningful names
// instead of "item" , "expression" would have been a better choice
// the same applies to i1
int i1;
for(int i=0;i<20;i++)
{
if(item[i]='+') // this should be if (item[i] == '+')
{
i1 = atoi(item[i-1]); // if using C++ y use old C functions
// also i think atoi works with only null terminated strings
item[i]=item[i-2]+item[i-1];
top=top-2;
i=i-2;
stack[top] = item[i];
}
else
{
stack[top] = item[i];
top++;
}
}
}Bye.
Last edited by ~s.o.s~; Jul 25th, 2006 at 3:37 pm.
I don't accept change; I don't deserve to live.
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
![]() |
Similar Threads
- char+int????? (C++)
- How to LPCTSTR Convert to char * (C++)
- pls help me to convert char to integer. (C)
Other Threads in the C++ Forum
- Previous Thread: Someone who wants to learn C++ with me?
- Next Thread: musical tones
Views: 16667 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search simple sort sorting spoonfeeding string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






