strcmp for NULL character
-
Hi, In my coding i initialized null to CString.Im comoaring NULL character to that string.But it returns wrong value.See my code.
CString ExeMonFile=_T("");
int NoExeMonFile=1;
if(strcmp(ExeMonFile,"")!=0)
NoExeMonFile=0;By debugging the NoExeMonFile became 0. Then i found that ExeMonFile is initialized to some other text.How its possible. I declared ExeMonFile Globally. Im using VS2008.Whats the betterway to initialize CString .
Anu
-
Hi, In my coding i initialized null to CString.Im comoaring NULL character to that string.But it returns wrong value.See my code.
CString ExeMonFile=_T("");
int NoExeMonFile=1;
if(strcmp(ExeMonFile,"")!=0)
NoExeMonFile=0;By debugging the NoExeMonFile became 0. Then i found that ExeMonFile is initialized to some other text.How its possible. I declared ExeMonFile Globally. Im using VS2008.Whats the betterway to initialize CString .
Anu
Anu_Bala wrote:
CString ExeMonFile=_T("");
You dont need to intilalize
CString
, the constructor ofCString
will take of this. By default it will set theCString
to an empty string.Anu_Bala wrote:
if(strcmp(ExeMonFile,"")!=0)
The best way to check wheather a
CString
is empty or not is to use theIsEmpty()
function ofCString
.nave [My Articles] [My Blog]
-
Anu_Bala wrote:
CString ExeMonFile=_T("");
You dont need to intilalize
CString
, the constructor ofCString
will take of this. By default it will set theCString
to an empty string.Anu_Bala wrote:
if(strcmp(ExeMonFile,"")!=0)
The best way to check wheather a
CString
is empty or not is to use theIsEmpty()
function ofCString
.nave [My Articles] [My Blog]
-
But in my applcaiton in default it will assign to some "BL001" not only for this CString. Whatever CString im using in this applcation all are initialized to this "BL001". Just i converted VC++6.0 to VS2008. After that only this problem arised.
Anu
How did you verify the content in the CString? while debugging or you tried to display the content in some message box? If the optimisation is no disabled, there is a chance that the debugger show incorrect value while debugging( check project properties->c++->optimization )
nave [My Articles] [My Blog]
-
How did you verify the content in the CString? while debugging or you tried to display the content in some message box? If the optimisation is no disabled, there is a chance that the debugger show incorrect value while debugging( check project properties->c++->optimization )
nave [My Articles] [My Blog]
My optimization setting is Disabled (/Od) While debugging while keeping cursor on this CString variable it shows "BL001" Actually BL001 is one term stored in char szModelName[10]. But why its get copied in all CString varialbes used in various classes. Even in some dialog,in edit boxes it displayed to BL001 instead of empty box.
Anu
-
My optimization setting is Disabled (/Od) While debugging while keeping cursor on this CString variable it shows "BL001" Actually BL001 is one term stored in char szModelName[10]. But why its get copied in all CString varialbes used in various classes. Even in some dialog,in edit boxes it displayed to BL001 instead of empty box.
Anu
-
Thats bit strange. Some memory corruption I guess. Let me ask. Have you called CString::GetBuffer() at some place and didnt call CString::Releasebuffer()?
nave [My Articles] [My Blog]
When i searched for GetBuffer() in my coding,i get four or five GetBuffer() lines. But unfortunately there is no ReleaseBuffer(). But where i using GetBuffer(),that CString is not related to above mentioned CString. Im confused may it cause problem to all CString varialbles?
Anu
-
Hi, In my coding i initialized null to CString.Im comoaring NULL character to that string.But it returns wrong value.See my code.
CString ExeMonFile=_T("");
int NoExeMonFile=1;
if(strcmp(ExeMonFile,"")!=0)
NoExeMonFile=0;By debugging the NoExeMonFile became 0. Then i found that ExeMonFile is initialized to some other text.How its possible. I declared ExeMonFile Globally. Im using VS2008.Whats the betterway to initialize CString .
Anu
You can use CString's Compare() function.
-
Hi, In my coding i initialized null to CString.Im comoaring NULL character to that string.But it returns wrong value.See my code.
CString ExeMonFile=_T("");
int NoExeMonFile=1;
if(strcmp(ExeMonFile,"")!=0)
NoExeMonFile=0;By debugging the NoExeMonFile became 0. Then i found that ExeMonFile is initialized to some other text.How its possible. I declared ExeMonFile Globally. Im using VS2008.Whats the betterway to initialize CString .
Anu
Anu_Bala wrote:
CString ExeMonFile=_T(""); int NoExeMonFile=1; if(strcmp(ExeMonFile,"")!=0) NoExeMonFile=0;
Why do you mix the
_T("")
literal with the""
one? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Hi, In my coding i initialized null to CString.Im comoaring NULL character to that string.But it returns wrong value.See my code.
CString ExeMonFile=_T("");
int NoExeMonFile=1;
if(strcmp(ExeMonFile,"")!=0)
NoExeMonFile=0;By debugging the NoExeMonFile became 0. Then i found that ExeMonFile is initialized to some other text.How its possible. I declared ExeMonFile Globally. Im using VS2008.Whats the betterway to initialize CString .
Anu
Bytes following a null byte are not compared.
Of one Essence is the human race thus has Creation put the base One Limb impacted is sufficient For all Others to feel the Mace (Saadi )
-
When i searched for GetBuffer() in my coding,i get four or five GetBuffer() lines. But unfortunately there is no ReleaseBuffer(). But where i using GetBuffer(),that CString is not related to above mentioned CString. Im confused may it cause problem to all CString varialbles?
Anu
-
Anu_Bala wrote:
CString ExeMonFile=_T(""); int NoExeMonFile=1; if(strcmp(ExeMonFile,"")!=0) NoExeMonFile=0;
Why do you mix the
_T("")
literal with the""
one? :)If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
My problem is ExeMonFile is not initialized to null, Its have someother value. In my applciation all Uninitialized CString Value have this ex:BL001 string. Even when initialized with _T(""), it doesnot get initialized.
Anu
Anu_Bala wrote:
Even when initialized with _T(""), it doesnot get initialized.
You know that is a nonsense, doesn't you? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]