超级小白求助!!!quq为啥我的字符串拷贝完了之后是乱码

阿言言言言言 2019-03-05 10:08:46
新人通讯录作业的一个函数出现了问题quqqqqqqqqqq
函数功能是交换输入节点的内容
求求大佬们帮帮我趴orz
函数如下:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char yes[]={'y','e','s','\0'};
char no[]={'n','o','\0'};
char na[20];
char ge[3];
char nu[8][13];
char ad[50];
int da[3];
typedef struct information{
char name[20];
char gender[3];
char number[8][13];
char address[50];
int date[3];
struct information *next;
} information;
void exchange(information *p,information *q){
char na2[20];
char ge2[3];
char nu2[8][13];
char ad2[50];
int da2[3];
int i,j;
memcpy(na,q->name,sizeof(q->name));
memcpy(ge,q->gender,sizeof(q->gender));
memcpy(nu,q->number,sizeof(q->number));
memcpy(ad,q->address,sizeof(q->number));
memcpy(da,q->date,sizeof(q->date));
memcpy(na2,p->name,sizeof(p->name));
memcpy(ge2,p->gender,sizeof(p->gender));
memcpy(nu2,p->number,sizeof(p->number));
memcpy(ad2,p->address,sizeof(p->address));
memcpy(da2,p->date,sizeof(p->date));
memcpy(p->name,na,sizeof(na));
memcpy(p->gender,ge,sizeof(ge));
memcpy(p->number,nu,sizeof(nu));
strcpy(p->address,ad);//就是这一步出现错误,将ad的值赋给p->address结果链表内的值输出之后是乱码
memcpy(p->date,da,sizeof(da));
strcpy(q->name,na2);
strcpy(q->gender,ge2);
strcpy(q->address,ad2);
for(i=0;i<=7;i++){
for(j=0;j<=13;j++){
p->number[i][j]=nu2[i][j];
}
}
for(i=0;i<=2;i++){
p->date[i]=da2[i];
}
printf("%s\n",ad);//这个是用来检查错误的
}
...全文
110 2 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
自信男孩 2019-03-06
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char yes[]={'y','e','s','\0'};
char no[]={'n','o','\0'};

char na[20];
char ge[3];
char nu[8][13];
char ad[50];
int da[3];

typedef struct information{
char name[20];
char gender[3];
char number[8][13];
char address[50];
int date[3];
struct information *next;
} information;

void exchange(information *p,information *q)
{
char na2[20];
char ge2[3];
char nu2[8][13];
char ad2[50];
int da2[3];
int i,j;
#if 0
memcpy(na,q->name,sizeof(q->name));
memcpy(ge,q->gender,sizeof(q->gender));
memcpy(nu,q->number,sizeof(q->number));
memcpy(ad,q->address,sizeof(q->number));
memcpy(da,q->date,sizeof(q->date));
memcpy(na2,p->name,sizeof(p->name));
memcpy(ge2,p->gender,sizeof(p->gender));
memcpy(nu2,p->number,sizeof(p->number));
memcpy(ad2,p->address,sizeof(p->address));
memcpy(da2,p->date,sizeof(p->date));
memcpy(p->name,na,sizeof(na));
memcpy(p->gender,ge,sizeof(ge));
memcpy(p->number,nu,sizeof(nu));
strcpy(p->address,ad);//就是这一步出现错误,将ad的值赋给p->address结果链表内的值输出之后是乱码
memcpy(p->date,da,sizeof(da));
strcpy(q->name,na2);
strcpy(q->gender,ge2);
strcpy(q->address,ad2);
for(i=0;i<=7;i++){
for(j=0;j<=13;j++){
p->number[i][j]=nu2[i][j];
}
}
for(i=0;i<=2;i++){
p->date[i]=da2[i];
}
#else
memcpy(p, q, sizeof(information));
#endif
//printf("%s\n",ad);//这个是用来检查错误的
printf("%s\n", p->address);//这个是用来检查错误的
}


试一下这种方法。
阿言言言言言 2019-03-05
  • 打赏
  • 举报
回复
好像就是字符串赋给数组的时候出问题啦!!!我该怎么办呀orz
H Y D R A (c) 2001-2012 by van Hauser / THC http://www.thc.org co-maintained by David (dot) Maciejak @ gmail (dot) com BFG code by Jan Dlabal Licensed under GPLv3 (see LICENSE file) INTRODUCTION ------------ Number one of the biggest security holes are passwords, as every password security study shows. This tool is a proof of concept code, to give researchers and security consultants the possiblity to show how easy it would be to gain unauthorized access from remote to a system. THIS TOOL IS FOR LEGAL PURPOSES ONLY! There are already several login hacker tools available, however none does either support more than one protocol to attack or support parallized connects. It was tested to compile cleanly on Linux, Windows/Cygwin, Solaris, FreeBSD and OSX. Currently this tool supports: AFP, Cisco AAA, Cisco auth, Cisco enable, CVS, Firebird, FTP, HTTP-FORM-GET, HTTP-FORM-POST, HTTP-GET, HTTP-HEAD, HTTP-PROXY, HTTPS-FORM-GET, HTTPS-FORM-POST, HTTPS-GET, HTTPS-HEAD, HTTP-Proxy, ICQ, IMAP, IRC, LDAP, MS-SQL, MYSQL, NCP, NNTP, Oracle Listener, Oracle SID, Oracle, PC-Anywhere, PCNFS, POP3, POSTGRES, RDP, Rexec, Rlogin, Rsh, SAP/R3, SIP, SMB, SMTP, SMTP Enum, SNMP, SOCKS5, SSH (v1 and v2), Subversion, Teamspeak (TS2), Telnet, VMware-Auth, VNC and XMPP. However the module engine for new services is very easy so it won't take a long time until even more services are supported. Your help in writing, enhancing or fixing modules is highly appreciated!! :-) HOW TO COMPILE -------------- For hydra, just type: ./configure make make install If you need ssh module support, you have to setup libssh on your system, get it from http://www.libssh.org, for ssh v1 support you also need to add "-DWITH_SSH1=On" option in the cmake command line. If you use Ubuntu, this will install supplementary libraries needed for a few optional modules: apt-get install

70,023

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧