
c语言编程 要用指针把两个字符串连接起来, 我这么编的不知道哪错了。求指教,求正解。谢谢
#include<stdio.h>voidmain(){chars[20],c[20];char*p,*q;p=s,q=c;printf("请输入一串字符:");gets...
#include<stdio.h>
void main()
{
char s[20],c[20];
char *p,*q;
p=s,q=c;
printf("请输入一串字符:");
gets(p);
printf("请输入一串字符:");
gets(q);
for(p=s;*p!='\0';p++)
for(q=c;*q!='\0';q++)
*p++=*q;
*p='\0';
printf("连接后的字符串为:%s\n",*p);
} 展开
void main()
{
char s[20],c[20];
char *p,*q;
p=s,q=c;
printf("请输入一串字符:");
gets(p);
printf("请输入一串字符:");
gets(q);
for(p=s;*p!='\0';p++)
for(q=c;*q!='\0';q++)
*p++=*q;
*p='\0';
printf("连接后的字符串为:%s\n",*p);
} 展开
3个回答
展开全部
#include<stdio.h>
#include <string.h>
void main()
{
char s[20],c[20],x[40],i,j;
char (*p)[20],(*q)[20];
p=&s,q=&c;
printf("请输入一串字符:");
gets(*p);
printf("请输入一串字符:");
gets(*q);
strcat(*p,*q);
printf("连接后的字符串为:%s\n",*p);
}
#include <string.h>
void main()
{
char s[20],c[20],x[40],i,j;
char (*p)[20],(*q)[20];
p=&s,q=&c;
printf("请输入一串字符:");
gets(*p);
printf("请输入一串字符:");
gets(*q);
strcat(*p,*q);
printf("连接后的字符串为:%s\n",*p);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
void main()
{
char s[100],c[20],d[20];
char *p,*q, *sp;
sp = s;
p = c;
q = d;
printf("请输入一串字符:");
gets(c);
printf("请输入一串字符:");
gets(d);
for (;*p != '\0';) {
*sp++ = *p++;
}
for (;*q != '\0';) {
*sp++ = *q++;
}
*sp = '\0';
printf("连接后的字符串为:%s\n",s);
}
{
char s[100],c[20],d[20];
char *p,*q, *sp;
sp = s;
p = c;
q = d;
printf("请输入一串字符:");
gets(c);
printf("请输入一串字符:");
gets(d);
for (;*p != '\0';) {
*sp++ = *p++;
}
for (;*q != '\0';) {
*sp++ = *q++;
}
*sp = '\0';
printf("连接后的字符串为:%s\n",s);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
第一个for后加分号隔开试试
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询