Skip to content

Instantly share code, notes, and snippets.

@vadimkantorov
Created September 12, 2024 20:13
Show Gist options
  • Save vadimkantorov/8a825f67bfe64e7e12478db0e9a70fb5 to your computer and use it in GitHub Desktop.
Save vadimkantorov/8a825f67bfe64e7e12478db0e9a70fb5 to your computer and use it in GitHub Desktop.
Demo of strrchr C function
// https://en.cppreference.com/w/c/string/byte/strrchr
#include <stdio.h>
#include <string.h>
int main(int argc, char* argv[])
{
if(argc < 2)
return -1;
const char pathsep = '/';
const char* path = argv[1];
const char* slash = strrchr(path, pathsep);
const char* basename = slash ? (slash + 1) : path;
puts(basename);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment