c - copying a string from one pointer to another -
#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; < argc; i++){ //if alternative if(argv[i][0] == '-'){ switch(argv[i][0]){ default:; } //otherwise, should 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 pointer '.' in argument, using strrchr, , find_end returns pointer '\0' in argument.
it compiles, segmentation fault. i'm trying capture file extension string, , compare extension other strings.
char *file_extension[10]; ^
you're not declaring file_extension
right. need char array, not array of pointers. drop *
.
c pointers
No comments:
Post a Comment