无法将字符串输入结构

时间:2017-12-18 13:32:32

标签: c string struct scanf

我有一个头文件structs.h如下:

#include <stdio.h>

typedef struct
{
    char *name;
}
student;

在文件structs.c中,

#include <stdio.h>
#include "structs.h"

int main()
{
    student students[3];

    scanf("%s", &students[0].name);

    return 0;

}

scanf语句给出错误,因为它表示%s的类型为char *,但参数的类型为char **。删除&amp;给出了分段错误。

我怎么写这个?它是一个struct变量数组中的数组,但它应该能够输入...

0 个答案:

没有答案
相关问题