strrchr.c 561 B

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