本文介绍了结构作为函数参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好, 嗯,似乎我对结构的挣扎仍在继续。在让我的代码工作后不久,我想将整个结构传递给一个函数。麻烦的是,我想使用如下所述的typedef: ============================= =================== 展开 | 选择 | Wrap | 行号 解决方案 你在哪里放了函数find_departure的原型。 它是在main函数之前吗? 那个函数的主体在哪里? Raghu 您如何期望函数find_departure知道调度数组中有多少元素?你必须传递数组中元素的数量。 C支持将结构作为参数传递并具有结构返回值;但根据我的经验,如果您在调用者和被调用者之间来回传递指向结构的指针,那么生活会更好。 (这实际上就是你在做什么,但你试图隐藏它。) @nexusdarkblue 否。它的意思与读取完全一样 - 编译器不知道find_departure是什么。是,无论是否错误:你声明你在其他地方运作,并且不将它包含在你的源文件中,称为这就是我想要调用我的函数的方式:因为它只包括stdio.h Hello everyone,Well, it seems my struggles with structures have continued. Shortly after getting my code to work, I wanted to pass the entire structure into a function. Trouble is, I want to use a typedef as described below:================================================ Expand|Select|Wrap|Line Numbers 解决方案 Where u have put the prototype of the function find_departure. Is it before the main function ?And where is the body of that function?RaghuHow do you expect function find_departure to know how many elements are in the schedule array? You have to pass it the number of elements in the array.C supports passing structures as arguments and having structure return values; but in my experience life is better if you instead pass pointers to structures back and forth between caller and callee. (That''s actually pretty much what you''re doing, but you''re trying to hide it.)@nexusdarkblueNo. It means exactly as it reads - compiler has no idea what "find_departure" is, whether it wrong or not: you declare you function somewhere else and don''t include it into your source file called "And here is how I wanted to call my function:" as it includes only "stdio.h" 这篇关于结构作为函数参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-05 20:37