#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);
find_dot返回指向'。'的指针。在参数中,使用strrchr,并且find_end返回指向参数中'\ 0'的指针。
它编译,但我遇到了分段错误。我要做的就是将文件扩展名捕获为字符串,并将该扩展名与其他字符串进行比较。
答案 0 :(得分:1)
char *file_extension[10]; ^
您没有声明file_extension
正确。你需要一个char数组,而不是一个指针数组。放下*
。