|
Hi everybody..
I am doing project on gsm modem.i am reading msg from sim.that read message i want to store into database.for that i have split that sentence so please tell me how to do that.. i am doing like this..
char str[1000];
strcpy(str,m_sResults);
MessageBox(str);
char delims[] = ",";
char* result;
result = strtok( str, delims );
while(result != NULL )
{
MessageBox(result);
result = strtok( NULL, delims );
}
but doing like this is impossible to store the values.so i want to store in different variables.please help me out.
in m_sResults the sentence is
AT+CMGR=1
+CMGR: "REC READ","919860716641","P apu.soni","08/05/22,19:05:34+34",145,4,0,0,"919890081132",145,106
Call me when you reach to your pg... I on the way to room..
OK
please help me.
thanks in advance,
savitri
|
|
|
|
|
Don't use strtok since internally it uses a static buffer which will cause problem with calls from multiple threads or simultaneous calls on different strings.
Instead use strtok_s/_tcstok_s, a demo -> http://www.tenouk.com/cpluscodesnippet/viewtopic.php?p=474[^]
Use vector<string> to store strings that are tokenized by this function.
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
|
Graham Bradshaw wrote: Mutliple threads is OK, apparently.
Thanks Graham!
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
don't use the token related functions for delimited file streams as they are dumb when faced with somthing like...
One,Two,Three,,,Six,Seven,...
It treats the three consecutive commas as one which could lead to unexpected results if those delimiters should be treated as "nothing" values for their respective indexes.
|
|
|
|
|
You can also use stringstream to parse strings. Since I couldn't find a reference, i wrote a quick sample. Check it below.
#include "string"
#include "vector"
#include "sstream"
...
string sResult(_T("Hello,can,you,split,me?"));
istringstream ResultParser( sResult );
string sToken;
vector<string> vResults;
while ( getline( ResultParser, sToken, ',' ))
{
vResults.push_back( sToken );
}</string>
Regards,
Jijo.
_____________________________________________________
http://weseetips.com[ ^] Visual C++ tips and tricks. Updated daily.
|
|
|
|
|
Hi. I have a little question:
I need to convert a memory direction printed on a CString variable, to a LPVOID variable. Example:
CString auxstr;
auxstr.Format(_T("%p"),p_Stereo);
LPVOID pointer = (LPVOID) ??????? variter->second.value;
I don't know how to convert this string to be able to cast it as a LPVOID. Anyone knows how? Thanks.
Ricard
|
|
|
|
|
Well as the pointer adresses are 0xADRESS, should you not convert from CString into Hex and then make the assignment?
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Yes, I suppose I should. But I can`t find this conversion (from cstring to hex). Is this from the atoi, atof...family? Can't find this.
Thank you so much.
|
|
|
|
|
Use strtol function. Specify base as 16.
e.g.
const long Val = strtol( "0xffff", NULL, 16 );
Nibu thomas
Microsoft MVP for VC++
Code must be written to be read, not by the compiler, but by another human being.
Programming Blog: http://nibuthomas.wordpress.com
|
|
|
|
|
This works perfectly....but as you can see, now i have many doubts for it to be the best solution. The overall plan, not yours.
Thank you..
|
|
|
|
|
The question, why do you store the address in a CString object in the first place ? Can't you simply store it directly in your LPVOID pointer ? It seems a bit crazy to use a CString in between.
|
|
|
|
|
No i can't. It's the way my program sends information between program blocks. In most cases they just send numbers or strings, but now i need to send an object.
|
|
|
|
|
Yeah, but why do you store that address in a CString instead of simply sending the address ? You can only exchange CString objects ?
|
|
|
|
|
Ritxi wrote: It's the way my program sends information between program blocks.
Basically your 'programs blocks' communicate via e-mail. This is crazy programming, isn't it?
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
|
|
|
|
|
CPallini wrote: This is crazy programming, isn't it?
I don't know if that is the case, but client/boss specifications sometimes (more than desirable) are "crazy"
Greetings.
--------
M.D.V.
If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about?
Help me to understand what I'm saying, and I'll explain it better to you
“The First Rule of Program Optimization: Don't do it. The Second Rule of Program Optimization (for experts only!): Don't do it yet.” - Michael A. Jackson
Rating helpfull answers is nice, but saying thanks can be even nicer.
|
|
|
|
|
Yes they are....but it's been my design. so...i am.
|
|
|
|
|
Nelek wrote: but client/boss specifications sometimes (more than desirable) are "crazy"
I agree, indeed they are often crazy. Anyway communication details between program blocks should not be affected by client/boss specification, since it is matter of technical implementation.
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
|
|
|
|
|
Maybe...i might be some stupid...maybe i change it all....
Ok. I've been thinking (it's not my best quality ). I' going to define two kind of communications. Messages and pointers. SCALABILITY! I'm a genious!!! Thank you all.
|
|
|
|
|
I think you need to view that at a higher level. Why in the first case do you need such "communication" mechanism ? Which 'parts' of your software needs to communicate and why ?
Ask yourself the correct question, this will already give some clues for a potential solution.
|
|
|
|
|
I agree. I'm not programming it as you might think...
I'm developing a part of an artifitial vision software. I want to command all the staff throught a flow chart editor (block diagrams). I want it all flexible and i need a mechanism to communicate the blocks.
Now, i've found a solution, but it's time to analize if it's the best solution.
Thanks for all your opinions. They all have helped me!
|
|
|
|
|
Ritxi wrote: I'm not programming it as you might think...
Possibly you're programming it as we fear you're doing.
(just kidding)
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
|
|
|
|
|
Ritxi wrote: Messages and pointers
Maybe numbers too. Good luck!
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
|
|
|
|
|
Those emails are encrypted with blowfish and the cypher is sent as a separate email. So, everything should be fine.
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
how to print a character in the dialog box, which is pressed through keyboard.
|
|
|
|