[英]How to combine two character type variables
考虑iam创建两个变量
char a1,b1,c1; /*consider that im assigning*/
a1='a',b1='b';
/* now i want to combine a1 and b1 and assign to c1
i.e c1='ab' pls suggest me the code to do that.
Dont suggest any complex code im a begineer.
您不能使用常规char
变量。 要执行您想要的操作,您应该使用char
数组:
char a1, b1, c1[2];
a1 = 'a';
b1 = 'b';
c1[0] = a1;
c1[1] = b1;
您不能在char variable
存储两个字符(该char variable
只有1个字节)。
使用char数组并使用sprintf
或snprintf
char c1[3];
sprintf(c1,"%c%c",a,b); // or snprintf(c1,sizeof c1,"%c%c",a,b);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.