转换arrayof字符字符串 [英] convert arrayof characters to string

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

问题描述

我用C语言编写code。


  1. 烧焦一个[​​] = {P,R,A,D,E,E,P} 结果
    我想补充 0 / 末使它的字符串。结果
    或者是有使它比在结束了吗?

  2. 添加另外null字符串的方法
  3. 的char * A =普拉迪普; 结果
    通过在末尾添加空将它转换为字符串



解决方案

您不能更改数组的大小 A ,所以你不能一个空终止添加到它。你可以改变声明:

 的char a [] =普拉迪普;

这将暗示加空终止符。或者:

 烧焦一个[​​] = {'P','R','A','D','E','E','P',0};

但字符串是简单和清晰。大多数,如果不是所有的C字符串的库函数需要一个空值终止字符串。

I am writing code in c language.

  1. char a[]={p,r,a,d,e,e,p}
    I want to add '0/' at the end to make it string.
    Or is there any method to make it string other than adding null at the end?

  2. char *a=pradeep;
    Convert this to string by adding null at the end

解决方案

You can't change the size of the array a so you cannot add a null terminator to it. You could change the declaration to:

char a[] = "pradeep";

which will implicitly add the null terminator. Or:

char a[] = { 'p', 'r', 'a', 'd', 'e', 'e', 'p', 0 };

but the string literal is simpler and clearer. Most, if not all, of the C string library functions require a null terminated string.

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

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