【发布时间】:2019-05-24 22:00:44
【问题描述】:
我是 c 的初学者,我想知道为什么我的函数 feed_struct 不复制我处理的字符串。这个函数 (feed_struct) 应该接受输入数据并将其放入我在全局定义的结构中。有谁知道为什么结构没有任何反应? 提前感谢您的帮助!
void feed_struct(struct student x, char name [20], char lname [20], double a, char adres [50], int b)
{
strcpy(x.name, name);
strcpy(x.lastname, lname);
x.number = a;
strcpy(x.adres, adres);
x.course = b;
}
int main (void)
{
struct student new_student;
feed_struct(new_student, "Peter", "Panther", 1230, "El-Lobo-Street 32", 72);
struct_print(new_student);
return 0;
}
【问题讨论】:
-
长话短说:您正在初始化
struct student的副本,原始文件不会更改。传递一个指针。