C中的链接列表

0 c

当我编译这个程序时,我在第45行(注释)中得到一个错误,说明了strcpy的不兼容隐式声明...我复制了部分代码,希望你们能帮助我解决这个问题

#include <stdio.h>

#include <stdlib.h>

#define strsize 30

typedef struct member
{int number;
char fname[strsize];
struct member *next;
}
RECORD;

RECORD* insert (RECORD *it);
RECORD* print(RECORD *it, int j);

int main (void)
{
int i, result;
RECORD *head, *p;
head=NULL;
printf("Enter the number of characters: ");
scanf("%d", &result);

for (i=1; i<=result; i++)
head=insert (head);
print (head, result);

return 0;

}

RECORD* insert (RECORD *it)

{

RECORD *cur, *q;
int num;
char junk;
char first[strsize];
printf("Enter a character:");
scanf("%c", &first);

cur=(RECORD *) malloc(sizeof(RECORD));

strcpy(cur->fname, first);
cur->next=NULL;

if (it==NULL)
it=cur;

else
{
q=it;
while (q->next!=NULL)
q=q->next;
q->next=cur;
}
return (it);
}
RECORD* print(RECORD *it, int j)
{
RECORD *cur;
cur=it;
int i;
for(i=1;i<=j;i++)
{
printf("%c \n", cur->fname);
cur=cur->next;
}
return;
}
Run Code Online (Sandbox Code Playgroud)

使用GCC来编译

And*_*ein 9

您可能需要添加

#include <string.h>
Run Code Online (Sandbox Code Playgroud)

获取strcpy()的声明.