|
guys,
What is meant by call back Function. why it is
called so?. Explain with some real time examples.
Thanks
Vivek.s
viveks
|
|
|
|
|
As the name says callback . Means call me back when you feel like calling me.
A good example would be timer functions. We pass a function as an argument and we forget about it. We write the necessary code inside this function.
When the timer fires this function will be called. Hence the name callback.
If you've used AfxBeginThread or SetTimer you will understand what this means.
Nibu thomas
Software Developer
|
|
|
|
|
assume: string s1 = "abcd"; string s2 = "2.53",
how to detect (code)that s2 representing a numeber, whereas s1 a character string ?
|
|
|
|
|
CString str="asd";-->return 0
CString str2="253";-->return 253
int index=atoi(str2);
-- modified at 0:14 Thursday 16th March, 2006
|
|
|
|
|
my question is how you know s2 is a digital ?
|
|
|
|
|
I tested this code if s1=abcd the return is 0
and for 2.53 return 253
|
|
|
|
|
how did you tested ? with which function or code segments?
|
|
|
|
|
Can you not read? He answered with atoi . It fails with a 0 return value if a numerical conversion is not possible.
--
The Blog: Bits and Pieces
|
|
|
|
|
Johann Gerell wrote: It fails with a 0 return value if a numerical conversion is not possible.
And what if the number was 0? It will still return 0 as if it failed.
I can't understand why people still use atof
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Nemanja Trifunovic wrote: I can't understand why people still use atof
Me neither, but that was not the point of my post.
I personally use
long strtol( const char *nptr, char **endptr, int base );
long wcstol( const wchar_t *nptr, wchar_t **endptr, int base ); with which a 0 return value can be checked against the endptr parameter to see if a conversion occurred or not.
--
The Blog: Bits and Pieces
|
|
|
|
|
Johann Gerell wrote: I personally use
long strtol( const char *nptr, char **endptr, int base );long wcstol( const wchar_t *nptr, wchar_t **endptr, int base );
with which a 0 return value can be checked against the endptr parameter to see if a conversion occurred or not.
Finally a voice of reason.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Brute force and pig ignorance - step through the string, checking:
(1) that every character is either a digit or a decimal point, and
(2) that there is at most one decimal point
It's only a bit more compliicated if you want to allow Hex numbers (0x....), etc.
Alternatively, try to use one of the string-to-real functions - maybe the return code will tell you if there is an error.
|
|
|
|
|
mrby123 wrote: how to detect (code)that s2 representing a numeber
Scan through the string and check using _istdigit . If a
particular character is a number then this function returns a non zero value.
mrby123 wrote: whereas s1 a character string ?
Same here too except use _istalpha .
Nibu thomas
Software Developer
|
|
|
|
|
how to use _istdigit or _istalpha ? give me a code segment ?
|
|
|
|
|
Code[^] segment.
Nibu thomas
Software Developer
|
|
|
|
|
I tried that those functions do not take a string as argument.
|
|
|
|
|
Exactly they take a single char.
That is what I said before. Scan through the string picking out each character and checking it.
Nibu thomas
Software Developer
|
|
|
|
|
I personally use
long strtol( const char *nptr, char **endptr, int base );
long wcstol( const wchar_t *nptr, wchar_t **endptr, int base ); with which a 0 return value can be checked against the endptr parameter to see if a conversion occurred or not.
--
The Blog: Bits and Pieces
|
|
|
|
|
Can anyone tell me how to write entries into "History Fodler" programmatically?
Thanks and Regards,
Anil
|
|
|
|
|
I have a Check Box in a dialog, I set "Disabled" as "True" in its properties. How can I enable it after I click a event handler during the program executing? If I want to disable it again, how can I do it?
What about a Radio Button? same way?
Thanks,
Joy Anne
|
|
|
|
|
Joy Anne wrote: How can I enable it after I click a event handler during the program executing? If I want to disable it again, how can I do it?
GetDlgItem(IDC_YOURCHECKBOX_ID)->EnableWindow(TRUE);
Nibu thomas
Software Developer
|
|
|
|
|
Just for the records:
Calling GetDlgItem is extremly bad style!
For enabling/disabling items in a program, you use the
ON_UPDATE_COMMAND_UI(IDC_YOURCHECKBOX_ID, OnUpdateYourCheckbox) idiom.
If you really need to manipulate the IDC_YOURCHECKBOX_ID-control, make a control variable and use this (as described by WhiteSky).
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
-- modified at 12:38 Thursday 16th March, 2006
|
|
|
|
|
jhwurmbach wrote: Calling GetDlgItem is extremly bad style!
I don't think so. What are the reasons?
Nibu thomas
Software Developer
|
|
|
|
|
Well, my statement may have come across a bit too strong.
But I believe that, in an object oriented environment, ou should use the object oriented way to do something.
By using the ID_SOMETHING resource constants directly, you are breaching confidentiality of the inner workings of the control-class.
You are working 'across' the MFC mechanisms, which I view as a bad thing when you have decided to use MFC.
"We trained hard, but it seemed that every time we were beginning to form up into teams we would be reorganised. I was to learn later in life that we tend to meet any new situation by reorganising: and a wonderful method it can be for creating the illusion of progress, while producing confusion, inefficiency and demoralisation."
-- Caius Petronius, Roman Consul, 66 A.D.
|
|
|
|
|
jhwurmbach wrote: Well, my statement may have come across a bit too strong.
No. I just wanted to know.
jhwurmbach wrote: But I believe that, in an object oriented environment, ou should use the object oriented way to do something.
True.
jhwurmbach wrote: By using the ID_SOMETHING resource constants directly, you are breaching confidentiality of the inner workings of the control-class.
Well GetDlgItem(ID...) returns a pointer to a CWnd object . I don't see any breach here.
jhwurmbach wrote: You are working 'across' the MFC mechanisms, which I view as a bad thing when you have decided to use MFC.
This is still MFC because it returns a CWnd pointer.
Well some advocate against using GetDlgItem but I personally like it.
Have you ever had problems with GetDlgItem , well I never had. I you had let please me know.
Nibu thomas
Software Developer
|
|
|
|