fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int ends_with(char str[], char end[]) {
  5. size_t sl = strlen(str), el = strlen(end);
  6.  
  7. if (sl < el) { return 0; }
  8.  
  9. for (size_t i = 1; i < el; i++) {
  10. if (str[sl - i] != end[el - i]) { return 0; }
  11. }
  12.  
  13. return 1;
  14. }
  15.  
  16. int main(void) {
  17. printf("%d\n", ends_with("abba.bmp", ".bmp"));
  18. printf("%d\n", ends_with("abba.png", ".bmp"));
  19. printf("%d\n", ends_with("", ".bmp"));
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 2160KB
stdin
Standard input is empty
stdout
1
0
0