在C中串联字符串 [英] concatenating strings in C

查看:63
本文介绍了在C中串联字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一种方法可以向字符串中添加一个值,而不是像1 + 1 = 2而是像1 + 1 = 11。

i was wondering if there was a way to add a value to a string, not like 1 + 1 = 2 but like 1 + 1 = 11.

推荐答案

我认为您需要字符串连接:

I think you need string concatenation:

#include <stdio.h>
#include <string.h>

int main() {
  char str1[50] = "Hello ";
  char str2[] = "World";

  strcat(str1, str2);

  printf("str1: %s\n", str1);

  return 0;
}

来自: http://irc.essex.ac.uk/www.iota-six.co.uk/c/g6_strcat_strncat .asp

这篇关于在C中串联字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆