converting CString to int

Started by
5 comments, last by puchur 20 years ago
Hello! I''ve got problem with converting CString into int This code -> CString age; int iAge; iAge=atoi((char *)(LPCTSTR)age); works badly because for age=345 in iAge I get 3 always the first digit Any ideas?
Advertisement
sprintf((LPCTSTR)age, "%d", &iAge);
Brianmiserere nostri Domine miserere nostri
quote:Original post by BriTeg
sprintf((LPCTSTR)age, "%d", &iAge);


Did you try this? It doesn''t make any sense given the original poster''s question.

Sorry, I haven''t had my morning coffee yet. That should be sscanf, not sprintf.
Brianmiserere nostri Domine miserere nostri
iage = atoi(age.GetBuffer(0));

-CProgrammer
quote:Original post by BriTeg
Sorry, I haven''t had my morning coffee yet. That should be sscanf, not sprintf.


Ahhhhh, yes that makes much more sense!
thanx

now it works much better

This topic is closed to new replies.

Advertisement