Skip to content

Instantly share code, notes, and snippets.

@joepadmiraal
Last active March 17, 2022 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joepadmiraal/31a6e10d4d0831a341291647795434a2 to your computer and use it in GitHub Desktop.
Save joepadmiraal/31a6e10d4d0831a341291647795434a2 to your computer and use it in GitHub Desktop.
C assignment
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main () {
char filename[50];
printf("Please enter a filename : ");
gets(filename);
int ext_size = 3;
char *extension;
extension = malloc(ext_size);
char* ptr = strrchr(filename, '.');
strncpy(extension, ptr, ext_size);
printf("The file extension is: %s", extension);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment