简体   繁体   English

c中的字符数组处理(复制指向字符数组的指针)

[英]character array handling in c (copy pointer to character array)

I have a pointer with type const char* FunctionName , How can I put that into a payload of type char payload[100] without any warning or errors? 我有一个类型的指针const char* FunctionName ,我怎样才能将它放入一个payload类型的char payload[100]没有任何警告或错误? Also the payload[0] is filled with character value already, so the space starting from payload[1] 另外, payload[0]已经用字符值填充,因此从payload[1]开始的空间

update: 更新:

I tried like this `strcpy((&payload[1]),FunctionName); 我试过这样的`strcpy((&payload [1]),FunctionName); is working now. 现在正在工作。

But Ihave one more question, how can accomodate the pointer(FunctionName) into the payload[1] ratherthan copying the entire string? 但是我还有一个问题,如何将指针(FunctionName)容纳到payload[1]不是复制整个字符串? through any assignment statement? 通过任何分配声明?

/R / R

strncpy(&payload[1], FunctionName, 98);
payload[99] = '\0';

should be safe in the case that FunctionName has more than 98 characters before the NULL terminator. 如果FunctionName在NULL终止符之前超过98个字符,则应该是安全的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM