Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将字符串从一个指针复制到另一个指针 #包括 #包括 #包括 char*find_dot(); char*find_end(); int main(int argc,char*argv[]){ 字符*文件扩展名[10]; int i; 对于(i=1;i_C_Pointers - Fatal编程技术网

将字符串从一个指针复制到另一个指针 #包括 #包括 #包括 char*find_dot(); char*find_end(); int main(int argc,char*argv[]){ 字符*文件扩展名[10]; int i; 对于(i=1;i

将字符串从一个指针复制到另一个指针 #包括 #包括 #包括 char*find_dot(); char*find_end(); int main(int argc,char*argv[]){ 字符*文件扩展名[10]; int i; 对于(i=1;i,c,pointers,C,Pointers,其中find_dot使用strrchr返回参数中“.”的指针,find_end返回参数中“\0”的指针 它可以编译,但我遇到了一个分段错误。我所要做的就是将文件扩展名捕获为字符串,并将该扩展名与其他字符串进行比较 您没有声明文件扩展名对。您需要的是字符数组,而不是指针数组。删除*您应该有字符数组,而不是字符数组*:字符文件扩展名[10]。记住也要复制\0。没想到!谢谢!还有一件事我忘了提,请看编辑:)我花了一整天的时间在这上面,谢谢大家,它终于起作用了!谢谢!! #include <std

其中find_dot使用strrchr返回参数中“.”的指针,find_end返回参数中“\0”的指针

它可以编译,但我遇到了一个分段错误。我所要做的就是将文件扩展名捕获为字符串,并将该扩展名与其他字符串进行比较


您没有声明
文件扩展名
对。您需要的是字符数组,而不是指针数组。删除
*

您应该有
字符数组
,而不是
字符数组*
字符文件扩展名[10]
。记住也要复制
\0
。没想到!谢谢!还有一件事我忘了提,请看编辑:)我花了一整天的时间在这上面,谢谢大家,它终于起作用了!谢谢!!
#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);
char *file_extension[10];
     ^