"John Smith" <js****@company.com> wrote in message
news:zK******************@twister.southeast.rr.com ...
: What's wrong with the use of atoi in the following code? Why do I
: get the error message:
:
: 'atoi' : cannot convert parameter 1 from 'char' to 'const char *'
:
:
: char cBuffer[9];
: void PushUnique(int);
:
: for(y = 0; y < 9; y++)
: {
: isF.getline(cBuffer,9);
What do you intend cBuffer to contain here?
I would think it is to contain the ascii representation
of a single number -- such as: "16384" .
When that is the case, a single call to atoi will extract
that number:
int i = atoi(cBuffer); // atoi takes a string, and
// returns the value (e.g. i=16384)
Note that strtoi supports better error reporting,
and shall usually be preferred to atoi.
: for(x = 0; x < 9; x++)
: bd.Cell[x][y].PushUnique(atoi(cBuffer[x]));
: }
Are you trying to convert each digit into an integer?
In this case, PushUnique( cBuffer[x] - '0' ); will do.
But then you need to do the following:
- make sure the read line is at least 9 characters
long, or handle shorter strings appropriately.
- BTW, if you need 9 characters then cBuffer must
be at least 10 chars long (null-termination of C strings).
- error handling: first check that each digit-character
c is actually a decimal digit: ( (c>='0') && (c<='9') )
Ivan
--
http://ivan.vecerina.com/contact/?subject=NG_POST <- email contact form
Brainbench MVP for C++ <>
http://www.brainbench.com