C语言中: strcat 函数

xzjxylophone 2010-09-09 10:49:37
strcat 函数怎么处理 汉字的问题
例如:


char dest[20] = {""};
char *hello = "hello";
char *world = "world";
strcat(dest, hello);
strcat(dest, world);
printf("%s\n", dest);
getch();
return 0;


这个会输出 hellowworld

但是如果我把char *hello = "hello";改成char *hello = "您好";

这个将会显示出什么结果了?
...全文
213 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
renyintang 2010-09-10
  • 打赏
  • 举报
回复
两码事嘛
NoneSec 2010-09-10
  • 打赏
  • 举报
回复
lovestefanie 2010-09-10
  • 打赏
  • 举报
回复
很多东西自己试一下就知道了
vipvvv 2010-09-10
  • 打赏
  • 举报
回复
这个是可以输出的!最好是编译一下
zengpingweb 2010-09-10
  • 打赏
  • 举报
回复
建议楼主编译一下。
evoloyeu 2010-09-10
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void) {

char dest[1024] = "hello";
strcat(dest,"您好");
printf("%s\n",dest);
}

输出结果:
rexevol@ubuntu:~/workspace/func/Debug$ ./func
hello您好
rexevol@ubuntu:~/workspace/func/Debug$
dingshaofengbinbin 2010-09-09
  • 打赏
  • 举报
回复

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void main()
{
char dest[20] = {""};
char *hello = "你好";
char *world = "world";
strcat(dest, hello);
strcat(dest, world);
printf("%s\n", dest);
}

结果:
你好world
十八道胡同 2010-09-09
  • 打赏
  • 举报
回复
楼主是一下就知道了
pengzhixi 2010-09-09
  • 打赏
  • 举报
回复
直接strcat就是了。
justkk 2010-09-09
  • 打赏
  • 举报
回复
汉字不汉字的没有关系吧,只是把第二个字符串拼接在第一个的后面而已
qrp_pig 2010-09-09
  • 打赏
  • 举报
回复
应该会输出汉字,
因为汉字和宽字符大于0x7F
ascii的范围是 0 - 0x7f
unicode汉字码是16位的,但是高位和低位都是大于0x7f的,所以系统可以认识出是汉字还是字符;
我的理解不管字符还是汉字构成的string,在strcat中都是按照uint8处理的
liutengfeigo 2010-09-09
  • 打赏
  • 举报
回复
zgjxwl 2010-09-09
  • 打赏
  • 举报
回复
swuxd 2010-09-09
  • 打赏
  • 举报
回复
xzjxylophone 2010-09-09
  • 打赏
  • 举报
回复
呵呵 已经试了
问题解决了。。。
谢谢大家帮忙了啊
canshui 2010-09-09
  • 打赏
  • 举报
回复
初始化时用""就是字符串的初始化方式!用strcat进行操作就可以了呀……

char *strcat(char *,char *);
它只关心参数的类型
东大坡居士 2010-09-09
  • 打赏
  • 举报
回复
看你的编译器是否支持中文

69,373

社区成员

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

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