我有一个我有问题的项目。因此,指令是我们假设仅在头文件中而不是c文件中进行编码。
这是我与以下部分混淆的部分:
void getName(Name *)-接收指向Name的指针并执行
如下所述。
•提示用户输入“名称”类型所需的成员数据。
首先,要求输入名字:
请输入联系人的名字:<
-读取并存储用户输入到适当的Name成员中的C字符串值
我知道如何在C文件中执行此操作,但是我不确定标头文件的工作方式。我的头文件中当前有什么
// Structure type Name declaration (Milestone 1)
struct Name {
char firstName[31];
char middleInitial[7];
char lastName[36];
};
// Structure type Address declaration
// Place your code here... (from Milestone 1)
struct Address {
char street[41];
int streetNumber[1];
int apartmentNumber[1];
char postalCode[8];
char city [41];
};
// Structure type Numbers declaration
// Place your code here... (from Milestone 1)
struct Numbers {
int cell[21];
int home[21];
int business[21];
};
// Structure type Contact declaration
// Place your code here... (from Milestone 3)
struct Contacts{
char name;
char address;
int number;
};
我想写些什么来从用户那里获取名称。 C文件为空,导致im仅应使用头文件。 (仅假设使用C文件来调用变量,显示标题,调用Contact函数getName来存储Name成员的值,等等)
最佳答案
从技术上讲,您可以在标头文件中编写整个getName()函数,因为C预处理程序会在编译前将整个标头复制粘贴到C文件中。