C++ problem: I have a char's array containing a number that I want to move to an int, how do I do that?
-
example... int a; char b[3]='123'; //(I dunno if this is even possible but the fact is I have a char array containing a many digits number) a=b; how do I do this?
-
Answer:
Okay, you can't store the sting in a char, but you can store it in an array of char[]; the syntax you are looking for is atoi int i = atoi("123"); #include <stdio.h> #include <stdlib.h> int main () { int i; char szInput [256]; printf ("Enter a number: "); fgets ( szInput, 256, stdin ); i = atoi (szInput); printf ("The value entered is %d. The double is %d.\n",i,i*2); return 0; }
aoc10010... at Yahoo! Answers Visit the source
Other answers
1. determine how many digits (if this is not fixed) 2. a=b[last]+b[secondlast]*10.....b[first]*… (this can be done in a loop)
unsigned char tempArr[4]='123'; int i=0, arrToInt=0; for(i=0;i<4;i++) arrToInt =(arrToInt<<8) | tempArr[i];
Related Q & A:
- After downloading attachments from emails i am not able to open them. How do i correct this problem?Best solution by Yahoo! Answers
- I want to change my look but how.Best solution by Yahoo! Answers
- I want to add my personal photos. how can i add it.
- Where can I check a British's passport?Best solution by Yahoo! Answers
- I want to move to Colorado. Any tips?Best solution by ask.metafilter.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.