C语言 怎样把二维字符串数组复制给一维字符串数组

下面的strcpy(),使用不成功!
求高手帮忙!
代码:#include<stdio.h>
#include<stdlib.h>
struct student
{
char Num[20];
char Nam[20];
char Dep[20];
char Sub[20];
char Brip[20];
char Address[100];
char Pnum[20];
struct student *next;
};
main()
{
struct student *p;
FILE *fp;
int a,i,j,c;
char b[7][20];
fp=fopen("D:通讯录.txt","rt");
if(fp==NULL)
{
printf("文件打开失败\n");
exit(0);
}
fscanf(fp,"%d",&c);
for(i=0;i<=6;i++)
{
for(j=0;;j++)
{
a=fgetc(fp);
if(a!=10)
b[i][j]=a;
else
{
b[i][j]='\0';
break;
}
}
}
printf("%d",c);
for(i=0;i<=6;i++)
{
printf("%s\n",b[i]);
}
strcpy(p->Num,b[0]);
strcpy(p->Nam,b[1]);
strcpy(p->Dep,b[2]);
strcpy(p->Sub,b[3]);
strcpy(p->Brip,b[4]);
strcpy(p->Address,b[5]);
strcpy(p->Pnum,b[6]);
printf("%s\n%s\n%s\n%s\n%s\n%s\n%s\n",p->Num,p->Nam,p->Dep,p->Sub,p->Brip,p->Address,p->Pnum);
}

第1个回答  2010-07-26
strcpy所在的头文件没有加载,开头加上#include <string.h>
就ok了。本回答被提问者采纳
相似回答