#include <stdio.h>
#include <string.h>
#include <stdlib.h>
char * find_dot();
char * find_end();
int main(int argc, char * argv[]){
char *file_extension[10];
int i;
for(i = 1; i < argc; i++){
//if an option
if(argv[i][0] == '-'){
switch(argv[i][0]){
default:;
}
//otherwise, should be the file
}else{
char *dot_location_ptr;
char *end_location_ptr;
char *filename_ptr = argv[i];
dot_location_ptr = find_dot(filename_ptr);
end_location_ptr = find_end(filename_ptr);
memcpy(file_extension, dot_location_ptr, end_location_ptr - dot_location_ptr);
Where find_dot returns a pointer to the ‘.’ in the argument, using strrchr, and find_end returns a pointer to the ‘\0’ in the argument.
It compiles, but I get a segmentation fault. All I’m trying to do is capture the file extension as a string, and compare that extension to other strings.
You’re not declaring
file_extensionright. You need a char array, not an array of pointers. Drop the*.