Hi.. I need a split function for Keil C51, as it is not available in the Keil uVision 2 library. Bye.
Split function like in C#, or VB.NET that splits any string into substrings on the basis of any recurring character in the string. For e.g. I've a GPS NMEA sentence $GPMRC,123455,A,23456.7554,N,60454.545,E,000.0,129.0,,,A*75
Now I want to break this string on behalf of ',' but there is no built-in function. The Microcontroller I am using is AT89C52. Regards.
Since this is Not C# or vb.Net You get to code it. There is probably C code on the net. A for or while loop works.
the included functions strchr(), strpos() and strrpos() may help.
"Now I want to break this string on behalf of ',' but there is no built-in function."
Yes there is -- strtok().
However, strtok() comes with some baggage (i.e., its own set of problems and limitations which have been discussed all over the searchable parts of the 'net).
I didn't find strtok() in library "strings.h". I am using Keil uVision 2. Is it available in it or in later versions. One more thing that we also need to consider RAM limitations for this split function. If this function does not exist in real, I think we should make it for others. what do you people suggest? Everyone should work and give example on forum, and we'll pick the best code.
"Everyone should work and give example on forum, and we'll pick the best code."
Yes that sounds like an excellent idea.
Attention: Every forum contributor must immediately post their suggested code so the OP can choose the winner.
Hey guys, I've just discovered that the Internet has some information on it and I found a website called google that can help you find things.
I did a search for strtok and got this:
www.google.co.uk/codesearch
So, to summarize:
You ask for a split, but totally forget that a split can be a split of files into smaller parts, a split of strings on separator tokens, a split of serial data into multiple channels, or to multiple listeners, ...
Always, always be very explicit whenever you ask for things. We can never read your mind.
Second: You want something - that exists in many incarnations on the net. But instead of looking for it, you cleverly suggests that we should either go out looking and post the results, or should spend time either writing new variants or cut and paste the variants we have already been using.
Now, why do you so desperately want us to do your work?
Memory consumption? If you are allowed to modify the original string, then you can settle for an array of pointers to the start addresses of the individual substrings - still stored in the original string.
Or you can do an incremental solution, similar to strtok(). And yes, the manual for strtok() is available on the net. And yes, Google will know where a large number of copies of this manual can be found.
Now, here is a suggestion for you:
You spend time to locate (or write) three or four different solutions.
Post your solutions here, and which one you selected. Also write a short note for each solution: Why you did/did not pick that one. What their individual merrits are and when you recommend/do not recommend them.
After that, we can supply comments to your comments, i.e. point out further reasons for selecting a specific solution. Now, off you go.
Everyone should work and give example on forum, and we'll pick the best code
what do you mean by this statement? who are you? the spirit of Saddam Hussain? Robert Mugabe? my potato? I hope we can credit this silly statement to a wrong choice of words... code it yourself and post it for people to tell you if it is good or not instead of orderingM (!) others to do your word.
p.s.
where is miss embedded when she's needed?
I'm here my luv!
What is it you want me to do?
ho it is so wonderful to have you back! I wonder: who are you really? Some gruesome possibilities crossed my mind (that is, you = one of the regular contributers to this forum...) so I discarded them for now! Please reveal yourself (and embark on this, what was it the last time, some kind of dance...?)
...one of the regular contributers to this forum...
For your sake, I hope you weren't thinking of Erik!
"If this function does not exist in real, I think we should make it for others. what do you people suggest?"
It does, so I suggest we make nothing and simply use what exists.
"Is it available ... in later versions."
Yes:
http://www.keil.com/support/man/docs/c51/c51_strtok.htm
as opposed to others, I do not hide who I am.
I stand by what I say and thus have no need to hide.
That others will not take the responsibility for their statements is their problem.
Erik