strrchr.c 559 B

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