get filename from a filepath


/ Published in: C
Save to your folder(s)

for cmdparsing


Copy this code and paste it in your HTML
  1. /* ------------------------------------------------------------------------------- *\
  2. | # get_filename_from_path : searches a given filepath for its name |
  3. | @param : char* to the existing filepath |
  4. | @return : char* to the found filename |
  5. \* ------------------------------------------------------------------------------- */
  6. char* get_filename_from_path(char* filepath) {
  7.  
  8. char *filename = (char*)calloc(1, sizeof(SIZE_FILENAME));
  9. filename = (strrchr(filepath, '/'))+1;
  10. printf(" found filename: %s \n", filename);
  11.  
  12. return filename;
  13.  
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.