将结构体数组作为函数参数传递
typedef struct What_if
{
char price [2];
} what_if ;
what_if what_if_var[100];
int format_input_records();
int process_input_records(what_if *what_if_var);
int format_input_records()
{
if (infile != NULL )
{
char mem_buf [500];
while ( fgets ( mem_buf, sizeof mem_buf, infile ) != NULL )
{
item = strtok(mem_buf,delims);
strcpy(what_if_var[line_count].trans_Indicator,item) ;
printf("\ntrans_Indicator ==== : : %s",what_if_var[line_count].price);
process_input_records(&what_if_var);
line_count=line_count+1;
}
}
}
int process_input_records(what_if *what_if_var)
{
printf("\nfund_price process_input_records ==== : : %s",what_if_var[line_count]->price);
return 0;
}
我在这里遇到错误,任何人都可以告诉我我在这里犯了什么错误吗?
不允许在类型“
struct {...}*
”和“struct {...}(*)[100]
”之间进行函数参数赋值。需要指向结构或联合的指针。
typedef struct What_if
{
char price [2];
} what_if ;
what_if what_if_var[100];
int format_input_records();
int process_input_records(what_if *what_if_var);
int format_input_records()
{
if (infile != NULL )
{
char mem_buf [500];
while ( fgets ( mem_buf, sizeof mem_buf, infile ) != NULL )
{
item = strtok(mem_buf,delims);
strcpy(what_if_var[line_count].trans_Indicator,item) ;
printf("\ntrans_Indicator ==== : : %s",what_if_var[line_count].price);
process_input_records(&what_if_var);
line_count=line_count+1;
}
}
}
int process_input_records(what_if *what_if_var)
{
printf("\nfund_price process_input_records ==== : : %s",what_if_var[line_count]->price);
return 0;
}
I am facing error here, can any one please tell me what is the mistake i done here?
Function argument assignment between types "
struct {...}*
" and "struct {...}(*)[100]
" is not allowed.Expecting pointer to struct or union.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
数组本质上已经是指向已分配数组长度的某个内存空间的指针。因此你应该简单地这样做:
没有
&
An array is intrinsically already a pointer to some space of memory where the length of the array has been allocated. Therefore you should simply do:
without
&
错误就在这里:
您正在获取数组的地址,这相当于
what_if**
,而该函数只获取what_if*
。请注意,您可能希望将数组的大小作为第二个参数传递给 process_input_records,以便该函数知道数组中有多少个元素:
The error lies here:
You're taking the address of an array, which is equivalent to
what_if**
, while the function takes onlywhat_if*
.Note that you probably want to pass the size of the array as a second parameter to
process_input_records
, so the function knows how many elements are in the array: