Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

atoi Problem

Status
Not open for further replies.

makaveliuk

Programmer
Dec 1, 2003
46
GB
I have got a really annoying problem that I just cannot solve, look at the following code:

char szCount[20];
memset(szCount, 0, sizeof(szCount));
memcpy(szCount, (void *)strPageCount.GetBuffer(strPageCount.GetLength()), strPageCount.GetLength());
m_iPageCount = atoi(szCount);

The strPageCount is a CString containing a 2 digit+ number, when I copy it, szCount contains all the digits but when I run the atoi() function, it only converts the first character.

I have also tried atoi(strPageCount) which doesn't work and strcpy instead of memcpy and atoi(strPageCount.GetBuffer(strPageCount.GetLength())) and none of those work.

Any ideas?
 
use the f debugger to see exactly what is inside.

Ion Filipski
1c.bmp
 
If you are sure that the first two chars are digits then here is what you have to do:
CString szPageCount="23...";
int m_iPageCount = atoi(szPageCount.Left(2)); // 23
If the szPageCount string contains non digits then it stop at the first one reached.

-obislavu-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top