2008/04/01

strstr test

[vuhung@g++]$gcc -Wall strstr.c
[vuhung@g++]$./a.out
p1 = ,Ten,2, toi
p2 = ,Ten,2, toi
p1 = ,2, toi
p2 = Ten,2, toi
p1 = 2, toi
p2 = , toi
p1 = (null)
p2 = toi
[vuhung@g++]$cat strstr.c
#include
#include

int main()
{
unsigned char *p1;
unsigned char *p2;

unsigned char string[20] = ",Ten,2, toi";

p1 = string;

p2 = strstr(p1, ",");

printf("p1 = %s\n", p1);
printf("p2 = %s\n", p2);

p2++;
p1 = strstr(p2, ",");

printf("p1 = %s\n", p1);
printf("p2 = %s\n", p2);

p1++;
p2 = strstr(p1, ",");

printf("p1 = %s\n", p1);
printf("p2 = %s\n", p2);

p2++;
p1 = strstr(p2, ",");

printf("p1 = %s\n", p1);
printf("p2 = %s\n", p2);

return 0;

}

0 件のコメント: