strrchr.c 506 B

123456789101112131415161718192021
  1. #include <string.h>
  2. #include <stdio.h>
  3. int main(void) {
  4. char s0[] = "hello, world";
  5. char* ptr = strrchr(s0, 'l');
  6. if (ptr != &s0[10]) {
  7. printf("%p != %p\n", ptr, &s0[10]);
  8. printf("strrchr FAIL , exit with status code %d\n", 1);
  9. return 1;
  10. }
  11. char s1[] = "";
  12. ptr = strrchr(s1, 'a');
  13. if (ptr != NULL) {
  14. printf("%p != 0\n", ptr);
  15. printf("strrchr FAIL, exit with status code %d\n", 1);
  16. return 1;
  17. }
  18. printf("strrch PASS, exiting with status code %d\n", 0);
  19. return 0;
  20. }