初学结构体,程序老是崩,求大神指点
#include "stdafx.h"#include"stdlib.h"
#include"assert.h"
#include"string.h"
typedef struct _PERSON
{
char *name;
int count;
}PERSON;
int main()
{
printf_s("请输入有几位候选人:");
int n;
scanf_s("%d", &n);
PERSON *p = (PERSON *)malloc(sizeof(PERSON)*n);
assert(p != NULL);
for (int j = 0; j < n; j++)
{
char *s = (char *)malloc(sizeof(char) * 20);
assert(s != NULL);
p[j].name = s;
printf_s("请输入有第%d候选人名字:", j + 1);
scanf_s("%s", s);
}
return 0;
}