-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestSTRCEP.c
55 lines (48 loc) · 1.15 KB
/
testSTRCEP.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
char * strsep(char **stringp, const char *delim)
{
char *s;
const char *spanp;
int c, sc;
char *tok;
if ((s = *stringp) == NULL)
return (NULL);
for (tok = s;;) {
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c) {
if (c == 0)
s = NULL;
else
s[-1] = 0;
*stringp = s;
return (tok);
}
} while (sc != 0);
}
/* NOTREACHED */
}
int main(){
const char *gga = {"$GPGGA,150430.200,2412.1234,N,12042.5678,E,1,7,1.32,186.5,M,15.9,M,,*52\r\n"};
char *token;
char *delim = ",*";
char *s = malloc(sizeof(char)*100), *c=s;
strcpy(s,gga);
for(token = strsep(&s,delim); token!=NULL ; token = strsep(&s, delim))
{
printf("%s\n",token);
}
//test is memory leak?
int i;
for(i=0;i<100;i++)
if(c[i]==0)
printf(" ");
else
printf("%c",c[i]);
printf("\n%s",gga);
free(c);
return 0;
}