Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/61.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.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
在C语言中按值调用函数_C_Arrays_Function_Pointers - Fatal编程技术网

在C语言中按值调用函数

在C语言中按值调用函数,c,arrays,function,pointers,C,Arrays,Function,Pointers,不知何故,我对C语言不太熟悉,我试图在这里调用主函数中的函数“func”,但它给了我编译错误。我试着在谷歌上搜索类似的例子,但还是出现了错误 #include <stdio.h> #include <stdint.h> #include <stdlib.h> struct str { int value; uint32_t ptr_next; }; void func(int arg, char* arr[]); int main() { i

不知何故,我对C语言不太熟悉,我试图在这里调用主函数中的函数“func”,但它给了我编译错误。我试着在谷歌上搜索类似的例子,但还是出现了错误

#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>

struct str {
  int value;
  uint32_t ptr_next;
};

void func(int arg, char* arr[]);

int main() {
  int Arg;
  char* Arr[1];

  func(Arg, *Arr[1]);

  return 0;
}

void func(int arg, char* arr[]) {
  int list;

  struct str r;

  FILE* file = fopen(arr[1], "rb");

  do {
    list = fread(&r, sizeof(struct str), 1, file);

    if (list > 0)
      printf("%d ", r.value);

    fseek(file, r.ptr_next, 0);

  }

  while ((r.ptr_next != 0) && (list > 0));
}

#包括
#包括
#包括
结构str{
int值;
uint32_t ptr_next;
};
void func(int arg,char*arr[]);
int main(){
int-Arg;
char*Arr[1];
func(Arg,*Arr[1]);
返回0;
}
void func(整型参数,字符*arr[]{
int列表;
结构strr;
FILE*FILE=fopen(arr[1],“rb”);
做{
list=fread(&r,sizeof(struct str),1,file);
如果(列表>0)
printf(“%d”,r值);
fseek(文件,r.ptr_next,0);
}
而((r.ptr_next!=0)和&(list>0));
}

问题是,如何用C语言调用函数?< /P> < P> C只支持按值调用函数,在C++中添加引用调用,使用<代码>和<代码>符号。< /P> 传递给函数的值是内存中的一个位置,一个指针。如果要将该内存位置的数据副本交给函数,则需要为其制作副本

//假设Arg和Arr已初始化。
字符*Arr2[];//为字符**创建一个存储位置。
Arr2=malloc(Arg*sizeof(char*);//在其中输入正确的字符数

对于(int e=0;eTry
func(Arg,Arr);
我想我是您最初的尝试您在索引1处传递了字母的字符(内容)。只需传递数组本身即可。
main
的参数通常称为
argc
argv