fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. static const char*
  5. get_file_ext(const char *filename) {
  6. const char *ext = strrchr(filename, '.');
  7. return (ext && ext != filename) ? ext : (filename + strlen(filename));
  8. }
  9.  
  10. int main() {
  11. char *files[] = {"a.c", ".a", "a", NULL };
  12.  
  13. for (char** f = files; *f != NULL; ++f)
  14. printf("ext: '%s'\n", get_file_ext(*f));
  15. }
  16.  
Success #stdin #stdout 0.01s 1720KB
stdin
Standard input is empty
stdout
ext: '.c'
ext: ''
ext: ''