永发信息网

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

答案:2  悬赏:0  手机版
解决时间 2021-02-13 12:50
  • 提问者网友:嗝是迷路的屁
  • 2021-02-12 22:29
下面的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);
}
最佳答案
  • 五星知识达人网友:梦中风几里
  • 2021-02-12 23:13
可以把二维字符串数组的元素重新读入一个中间的一维字符串数组中,再和后面的一维字符串数组进行比较;
全部回答
  • 1楼网友:时间的尘埃
  • 2021-02-13 00:47
strcpy所在的头文件没有加载,开头加上#include <string.h> 就ok了。
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯