|
I know its the CRT function atoi(). But its not working for some reason. Thats why I asked for a code snippet. Someone please helpme out.
Aljechin
|
|
|
|
|
perhaps you could post the code you have created, this would give us a better idea of what you are trying and where you may be going wrong.
|
|
|
|
|
Ok, I just tested what I thought and I was half right. atoi will stop at the first non-numerical char, so if your string start with letter you have to remove them.
char *txt = "MX2001";
char *buffer = new char[10];
int pos = 0;
int result;
for (int i=0;i<strlen(txt);i++) {
if ((txt[i] > 0x29)&&(txt[i] < 0x40)) {
buffer[pos] = txt[i];
pos++;
}
}
buffer[pos] = 0x00;
result = atoi(buffer);
Or if your string is fairly constant and always the first two are letter you could
result = atoi(&txt[2]);
-- modified at 1:50 Wednesday 22nd March, 2006
Don't forget to use delete or you will have memory leaks;
|
|
|
|
|
Here is a way to do that.
1. Get length of your CString.
2. Declare a char array of that length and copy your CString to that array.
3. Now the number can easily be extracted from that array.
Here is the code to copy CString to char array
int size = myCString.GetLength(); <br />
char *array =(char*)malloc(size + 1);<br />
strcpy(array, myCString);
If problem remains, do let us know.
Good Luck
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
Thank you all. Actually I had been a little dumb. I forgot I was doing a unicode build and should have used _wtoi function and not the atoi function .
Thanks for all of your kind replies.
Aljechin
|
|
|
|
|
Aljechin should have used _wtoi function and not the atoi function .
Always try to use tchar version of functions. Like _ttoi . This way you don't have to worry whether it's unicode or not.
Nibu thomas
Software Developer
|
|
|
|
|
Your welcome.
I wish more people would say thankyou after they have been helped and more people to state what they did wrong or how they fixed the problem. The message boards (not only this site) are filled with questions and no answers or gratitude. It makes searching for a solution a hard task.
|
|
|
|
|
You can always rank helpful replies (bottom right)
We Believe in Excellence
www.aqueelmirza.cjb.net
-- modified at 3:25 Wednesday 22nd March, 2006
|
|
|
|
|
CString str=_T("MX1200" );
int position;
for(int i=0 , str.length(),i++)
if (str.getat(i) <= '9') and (str.getat(i) >= '0')
{
position =i;
//exit;
}
str =str.left(position);
int yourInteger =atoi(LPCTSTR(str));
|
|
|
|
|
|
Hi All,
I had been trying out different websites/books to find out as to what the precompiled header file actually contains but I haven't found any answer.
If any one out there knows what goes in there and would bother to answer this question, I would be highly obliged.
|
|
|
|
|
MFCRookie wrote: If any one out there knows what goes in there and would bother to answer this question, I would be highly obliged.
Well what about stdafx.h .
These files are used to build a precompiled header file Projname.pch and a precompiled types file Stdafx.obj.
These files are located in the Projname directory. In Solution Explorer, Stdafx.h is in the Header Files folder, and Stdafx.cpp is located in the Source Files folder.
stdafx.h
An include file for standard system include files and for project-specific include files that are used frequently but are changed infrequently.
stdafx.cpp
Contains the preprocessor directive #include "stdafx.h" and adds include files for precompiled types. Precompiled files of any type, including header files, support faster compilation times by restricting compilation only to those files that require it. Once your project is built the first time, you will notice much faster build times on subsequent builds because of the presence of the precompiled header files.
Nibu thomas
Software Developer
|
|
|
|
|
Hi Nibu,
Thanks for your response. I would just like to instantiate on this info that you have provided. Could you please tell me whether my understanding is correct? Sorry to keep bugging you.
Let us assume that there is only one line in stdafx.h and that is #include stdio.h . Now, stdio.h contains a function fopen . Taking fopen just for example. Now, is it true that the pch will contain object code for fopen? If yes, then what will stdafx.obj contain? Will it just be the object version of the line
FILE* fopen(const char* filename, const char* mode) ?
|
|
|
|
|
I think that stdio.obj will contain the object code for fopen function and your stdafx.obj will contain only a reference to that function, if any. Good coding and good luck!
|
|
|
|
|
The PCH file contains a tokenized representation of the contents of all headers that were processed. This means all prototypes, definitions, declarations, enumerations, and macros. There is no object code in it. You can thing of it as the results of what is typically the first two passes of a compiler - the preprocessor and tokenizer.
|
|
|
|
|
Hi Rick,
Thanks a lot. Looks like this is what I was looking out for.
Thanks once again.
|
|
|
|
|
What is the difference between the two below
if( NULL != lpDispatch )
and
if( lpDispatch != NULL )
where LPDISPATCH lpDispatch ;
Thanks..
---
With best regards,
A Manchester United Fan
The Genius of a true fool is that he can mess up a foolproof plan!
|
|
|
|
|
Save My Soul - (SMS) wrote: What is the difference between the two below
if( NULL != lpDispatch )
and
if( lpDispatch != NULL )
where LPDISPATCH lpDispatch ;
Thanks..
To avoid making the following mistake...
if(lpDispath = NULL)
;
But if we use
if(NULL = lpDispath)
;
This is one of a kind of silly but serious bugs. It becomes difficult to trace them. So programmers play safe with this kind of coding. Helps but not always.
Nibu thomas
Software Developer
|
|
|
|
|
No difference in turms of result they both produce. In both cases NULL and IpDispatch are being compared with each other.
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
It's handy to use NULL first sometimes. If you have a fairly long if statement, maybe you are checking the return value of a dialog, sometimes the line will scroll of your page. If you had the NULL at the end, it would be out of view, whereas having it first it is in view.
It simply makes scrolling through your code a little easier.
|
|
|
|
|
I have a (hopefully) simple problem. I want to create a custom control in C++, with or without MFC, that i can compile into a dll and use that control elsewhere eg other MFC apps and a .NET app. Whats the easiest way to do this?
|
|
|
|
|
MrNed wrote: Whats the easiest way to do this?
By Creating an MFC Extension Dll.
Nibu thomas
Software Developer
|
|
|
|
|
But that project creates a CWinApp class. How do I say create a CButton derived class and use that as the custom control elsewhere?
|
|
|
|
|
Is there any way to get the list of favourites items we added to MSDN library installed in System?
(Like storing the book mark in IE?).
This will be useful when we format/reinstall OS
|
|
|
|
|
Well, I saw that the list of favourites from MSDN and the one from IE are the same. Do you have separate lists? Thanks in advance for your answer.
|
|
|
|