Last active
March 17, 2022 09:42
-
-
Save joepadmiraal/31a6e10d4d0831a341291647795434a2 to your computer and use it in GitHub Desktop.
C assignment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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