【发布时间】:2021-07-17 16:42:11
【问题描述】:
#include <stdio.h>
#include <string.h>
struct employee
{
char ename[20];
int sal;
};
struct employee accept(struct employee);
void display(struct employee);
void main()
{
struct employee e,f;
f=accept(e);
display(f);
}
struct employee accept(struct employee e)
{
printf("Enter employee name and his sal :");
gets(e.ename);
gets(e.sal);
}
void display(struct employee e)
{
printf("Employee name :");
puts(e.ename);
printf("Employee salary :");
puts(e.sal);
}
上面的代码是从用户那里获取详细信息,而不是按照它应该做的那样显示它。谁能帮我纠正一下?
【问题讨论】:
-
打开并注意,您的编译器警告(您的函数
accept()被定义为返回一个值,但它没有return语句)!您的缩进可能会更好一些,以便从鹰眼中看到代码结构。 -
我的编译器没有给出任何警告也没有错误
-
如果你的编译器没有给出警告,也许使用另一个? (也许改变命令行开关或配置就足够了……)
-
你永远不应该使用
gets()函数——它是far too dangerous to be used, ever!。 -
@AdityaBachu 你确定你在运行
-Wall -Wextra(或者你的编译器用来启用警告的任何东西)?
标签: c function struct gets puts