Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <string.h>
- #include <stdlib.h>
- char *strtok_fr (char *s, char delim, char **save_ptr)
- {
- char *tail;
- char c;
- if (s == NULL) {
- s = *save_ptr;
- }
- tail = s;
- if ((c = *tail) == '\0') {
- s = NULL;
- }
- else {
- do {
- if (c == delim) {
- *tail++ = '\0';
- break;
- }
- }while ((c = *++tail) != '\0');
- }
- *save_ptr = tail;
- return s;
- }
- char *strtok_f (char *s, char delim)
- {
- static char *save_ptr;
- return strtok_fr (s, delim, &save_ptr);
- }
- int main() {
- int counter = 0;
- char string[100] = "1,1,20200921214503.000,43.324205,11.327886,342.100,0.00,227.8,1,,2.8,2.9,0.9,,19,4,3,,37,,";
- // Extract the first token
- char * token = strtok_f(string, ',');
- char **NMEA = NULL;
- NMEA = malloc(21*sizeof(char*));
- while( token != NULL ) {
- printf( " %s\n", token ); //printing each token
- NMEA[counter] = token;
- token = strtok_f(NULL, ',');
- counter++;
- }
- for (int i = 0; i <= counter; i++) {
- printf("[%d] - %s\n", i, NMEA[i]);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement