Help reading string data from array

Hey guys, i’m doing a project right now with a Fona shield where i’m querying gps data and sending it over sms. I’m also trying to read sms buffers into a char array, and pull pieces of string data out of the sms array.

Two things

  1. I’m a pretty novice programmer

  2. I’m looking for a function that could pull string data from the buffer, much like the way scanf works in C, but I want to use a specific character for the pulling instead of whitespaces. I realize this is probably a basic function a lot of people know. I’m just new and have no idea how to process the stream without a function like this. Not sure i’d be skilled enough to create a function to do it either, but if that’s what i need, maybe someone could guide me and ill give it my best shot.

there is a topic by Robin2 Serial Input Basicswhich is very helpful.

  1. I'm looking for a function that could pull string data from the buffer, much like the way scanf works in C, but I want to use a specific character for the pulling instead of whitespaces.

Any C function, such as scanf(), can be called from an Arduino program.

scanf() is NOT limited to white spaces as delimiters.

Before we can help you choose/write this mysterious function, seeing an example of the input, and the desired output, would be essential.

PaulS:
Any C function, such as scanf(), can be called from an Arduino program.

scanf() is NOT limited to white spaces as delimiters.

Before we can help you choose/write this mysterious function, seeing an example of the input, and the desired output, would be essential.

Thank you both for the replies. PaulS i do know scanf can be used in python i’m just wondering how you designate the delimiter for a different character. I certainly don’t want you to write a function for me, i just want to know how to use scanf, generically, to use *any character as a delimiter. I’m not trying to be stupid or short or anything, i just want to take a crack at writing the function without help first… once i know how to use scanf correctly that is. Its just the best way for me build and learn at this point. I can definitely give you examples of the buffers and the intended output or capture.

Using a Fona 2g device, I have a buffer for incoming serial from the Fona named replybuffer[255].

When i query the gps, i get raw nema output in the buffer.

Data stream: <— +CGNSINF: 0,4043.576433,7400.316980,58.647405,20150601201258.000,64,12,0.548363,100.442406

Not entirely sure if the <— +CGNSINF: comes across with the stream or not, but i believe it does since its function code basically does a println of ‘gpsdata’ which gets called up three lines earlier like this:

char gpsdata[120];
fona.getGPS(0, gpsdata, 120);

Now i’m a noob, but i’m sure we can get rid of the '<— +CGNSINF: ’ by just calling the output into another array ignoring those first few bits? Then use scanf however using “,” as the separator.

I was doing some digging around on stackO and i think i figured out how to change the delimiter.

Output format is:

fixmode,longitude,latitude,altitude,utctime(yyyymmddHHMMSS),ttff,satellites,speed,course

scanf("%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]%[^,]", fixmode, longitude, latitude, altitude, utctime, ttff, satellites, speed, course);

What is the % designating here? Also what is the ^ designating in my brackets?

scanf parameters.

Again check out Robin2's example #5, it uses strtok() to parse the data and is probably exactly what you are looking for.

Deva_Rishi:
Again check out Robin2's example #5, it uses strtok() to parse the data and is probably exactly what you are looking for.

Probably not. The one thing that strtok() does not deal with is multiple delimiters in a row. A GPS sentence can have multiple delimiters in a row, particularly when the GPS doesn't have a fix.

OP: Look at how TinyGPS++ does the actual parsing, once it has a string to parse.