AkumaYin

C: GetFileExt

Jan 22nd, 2022 (edited)
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.60 KB | None | 0 0
  1. /* Return a string pointer to a filename's extension */
  2. char* GetFileExt(char* fileName)
  3. {
  4.     /* Initialize return pointer
  5.     (will contain address of the filename string's extension,
  6.     at the location of the '.' character) */
  7.     char* extPtr = NULL;
  8.  
  9.     do
  10.     {
  11.         /* If current position of the filename string is the '.' character,
  12.         update return pointer */
  13.         if (*fileName == '.')
  14.         {
  15.             extPtr = fileName;
  16.         }
  17.  
  18.     /* Continue until we reach the end of the filename string
  19.     (accounts for '.'s appearing in filenames before the extension) */
  20.     } while (*fileName++ != '\0');
  21.  
  22.     /* Return */
  23.     return extPtr;
  24. }
Add Comment
Please, Sign In to add comment