Task: Extract file extension

C: #include <assert.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>


char* file_ext(const char *string)
{
    assert(string != NULL);
    char *ext = strrchr(string, '.');

    if (ext == NULL)
        return (char*) string + strlen(string);

    for (char *iter = ext + 1; *iter != '\0'; iter++) {
        if (!isalnum((unsigned char)*iter))
            return (char*) string + strlen(string);
    }

    return ext;
}

int main(void)
{
    const char *testcases[][2] = {
        {"http:
        {"CharacterModel.3DS", ".3DS"},
        {".desktop", ".desktop"},
        {"document", ""},
        {"document.txt_backup", ""},
        {"/etc/pam.d/login", ""}
    };

    int exitcode = 0;
    for (size_t i = 0; i < sizeof(testcases) / sizeof(testcases[0]); i++) {
        const char *ext = file_ext(testcases[i][0]);
        if (strcmp(ext, testcases[i][1]) != 0) {
            fprintf(stderr, "expected '%s' for '%s', got '%s'\n",
                testcases[i][1], testcases[i][0], ext);
            exitcode = 1;
        }
    }
    return exitcode;
}










Fortran:       MODULE TEXTGNASH	
       CHARACTER*10 DIGITS		
       CHARACTER*11 DDIGITS		
       CHARACTER*13 SDDIGITS		
       CHARACTER*4  EXPONENTISH		
       CHARACTER*17 NUMBERISH		
       CHARACTER*16 HEXLETTERS		
       CHARACTER*62 DIGILETTERS		
       CHARACTER*26 LITTLELETTERS,BIGLETTERS	
       CHARACTER*52 LETTERS		
       CHARACTER*66 NAMEISH		
       CHARACTER*3  ODDITIES		
       CHARACTER*1 CHARACTER(72)	
       EQUIVALENCE			
     1  (CHARACTER( 1),EXPONENTISH,NUMBERISH),	
     2  (CHARACTER( 5),SDDIGITS),		
     3  (CHARACTER( 7),DDIGITS,NAMEISH),	
     4  (CHARACTER( 8),DIGITS,HEXLETTERS,DIGILETTERS),	
     5  (CHARACTER(18),BIGLETTERS,LETTERS),	
     6  (CHARACTER(44),LITTLELETTERS),		
     7  (CHARACTER(70),ODDITIES)		
       DATA EXPONENTISH /"eEdD"/	
       DATA SDDIGITS /"+-.0123456789"/	
       DATA BIGLETTERS    /"ABCDEFGHIJKLMNOPQRSTUVWXYZ"/	
       DATA LITTLELETTERS /"abcdefghijklmnopqrstuvwxyz"/	
       DATA ODDITIES /"_:#"/		

       CHARACTER*62 GOODEXT	
       EQUIVALENCE (CHARACTER(8),GOODEXT)
c       PARAMETER (GOODEXT = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"	
c     1                    //"abcdefghijklmnopqrstuvwxyz"	
c     2                    //"0123456789")			
       INTEGER MEXT		
       PARAMETER (MEXT = 28)	
       CONTAINS
        CHARACTER*(MEXT) FUNCTION FEXT(FNAME)	
         CHARACTER*(*) FNAME	
         INTEGER L1,L2		
          L2 = LEN(FNAME)	
          L1 = L2		
   10     IF (L1.GT.0) THEN	
            IF (INDEX(GOODEXT,FNAME(L1:L1)).GT.0) THEN	
              L1 = L1 - 1		
              GO TO 10			
            END IF		
            IF (FNAME(L1:L1).EQ.".") THEN	
              L1 = L1 - 1			
              GO TO 20				
            END IF		
          END IF		
          L1 = L2		
   20     FEXT = FNAME(L1 + 1:L2)	
        END FUNCTION FEXT	
      END MODULE TEXTGNASH	

      PROGRAM POKE
      USE TEXTGNASH

      WRITE (6,*) FEXT("Picture.jpg")
      WRITE (6,*) FEXT("http://mywebsite.com/picture/image.png")
      WRITE (6,*) FEXT("myuniquefile.longextension")
      WRITE (6,*) FEXT("IAmAFileWithoutExtension")
      WRITE (6,*) FEXT("/path/to.my/file")
      WRITE (6,*) FEXT("file.odd_one")
      WRITE (6,*)
      WRITE (6,*) "Now for the new test collection..."
      WRITE (6,*) FEXT("http://example.com/download.tar.gz")
      WRITE (6,*) FEXT("CharacterModel.3DS")
      WRITE (6,*) FEXT(".desktop")
      WRITE (6,*) FEXT("document")
      WRITE (6,*) FEXT("document.txt_backup")
      WRITE (6,*) FEXT("/etc/pam.d/login")
      WRITE (6,*) "Approved characters: ",GOODEXT
      END