C語言切割字串函式 strsep,分析 URL GET 引數
阿新 • • 發佈:2019-02-06
/*
*
* Author : appleboy
* Date : 2010.04.27
* Filename : strsep.c
*
*/
int main()
{
int len, nel;
char query[] = "user_command=appleboy&test=1&test2=2";
char *q, *name, *value;
/* Parse into individual assignments */
q = query;
fprintf(stderr, "CGI[query string] : %s/n", query) ;
len = strlen(query);
nel = 1;
while (strsep(&q, "&"))
nel++;
fprintf(stderr, "CGI[nel string] : %d/n", nel);
for (q = query; q < (query + len);) {
value = name = q;
/* Skip to next assignment */
fprintf(stderr, "CGI[string] : %s/n", q);
fprintf( stderr, "CGI[string len] : %d/n", strlen(q));
fprintf(stderr, "CGI[address] : %x/n", q);
for (q += strlen(q); q < (query + len) && !*q; q++);
/* Assign variable */
name = strsep(&value, "=");
fprintf(stderr, "CGI[name ] : %s/n", name);
fprintf(stderr, "CGI[value] : %s/n", value);
}
return 0;
}
*
* Author : appleboy
* Date : 2010.04.27
* Filename : strsep.c
*
*/
int main()
{
int len, nel;
char query[] = "user_command=appleboy&test=1&test2=2";
char *q, *name, *value;
/* Parse into individual assignments */
q = query;
fprintf(stderr, "CGI[query string] : %s/n", query)
len = strlen(query);
nel = 1;
while (strsep(&q, "&"))
nel++;
fprintf(stderr, "CGI[nel string] : %d/n", nel);
for (q = query; q < (query + len);) {
value = name = q;
/* Skip to next assignment */
fprintf(stderr, "CGI[string] : %s/n", q);
fprintf(
fprintf(stderr, "CGI[address] : %x/n", q);
for (q += strlen(q); q < (query + len) && !*q; q++);
/* Assign variable */
name = strsep(&value, "=");
fprintf(stderr, "CGI[name ] : %s/n", name);
fprintf(stderr,
}
return 0;
}