0012-strchr.c (526B)
1 #include <assert.h> 2 #include <stdio.h> 3 #include <string.h> 4 5 /* 6 output: 7 testing 8 done 9 end: 10 */ 11 12 int 13 main() 14 { 15 char *p, buf[] = "abcad"; 16 17 puts("testing"); 18 19 p = strchr(buf, 0); 20 assert(p == buf+5); 21 assert(*p == '\0'); 22 23 p = strchr(buf, 'a'); 24 assert(p == buf); 25 assert(*p == 'a'); 26 27 p = strchr(buf, 'd'); 28 assert(p == buf+4); 29 assert(*p == 'd'); 30 31 p = strchr(buf, 'c'); 32 assert(p == buf+2); 33 assert(*p == 'c'); 34 35 p = strchr(buf, 'h'); 36 assert(p == NULL); 37 38 p = strchr("", 'a'); 39 assert(p == NULL); 40 41 puts("done"); 42 43 return 0; 44 }