小编use*_*960的帖子

Readline从C中的控制台接受int

我想让readline接受一个int.完成此任务的最佳方法是什么?我没有接受字符串输入这样的问题:

 char *usrname; // define user input

 /* accept input */
 printf("Enter new name:");
 usrname = readline(NULL);
Run Code Online (Sandbox Code Playgroud)

我明白在接受输入之前有一个int需要对它进行一些错误检查.

c int input readline

3
推荐指数
1
解决办法
738
查看次数

从C中的函数分配struct

我在编写一个在C中分配结构的函数时遇到了问题.理想情况下,我希望函数使用传递给它的参数填充结构的字段.

我在头文件中定义了结构,如下所示:

typedef struct {
  char name[NAME_SIZE]; //Employee name
  int birthyear; //Employee birthyear
  int startyear; //Employee start year
} Employee;
Run Code Online (Sandbox Code Playgroud)

这就是我目前的功能:

void make_employee(char _name, int birth_year, int start_year) {
  Employee _name  = {_name,birth_year,start_year}; //allocates struct with name
} /* end make_employee function */
Run Code Online (Sandbox Code Playgroud)

关于如何实现这一目标的任何建议?

c struct function

2
推荐指数
2
解决办法
1万
查看次数

标签 统计

c ×2

function ×1

input ×1

int ×1

readline ×1

struct ×1