开发者

c strcpy copy to array of string

开发者 https://www.devze.com 2023-03-09 16:47 出处:网络
char strarr[5][10]; whe开发者_如何学JAVAn I use strcpy(strarr[0], src); try to copy contents from src to strarr[0] .I got seg fault.
char strarr[5][10];

whe开发者_如何学JAVAn I use

strcpy(strarr[0], src);

try to copy contents from src to strarr[0] .I got seg fault.

Is this wrong?

Thanks!


Unless you show us more code we can only assume src is more than the space availabe. Also it may be that src is not NUL-terminated.


It depends on what is the src pointer, and its length.


You need to use strncpy().

strncpy(dest[0], src, 10);

0

精彩评论

暂无评论...
验证码 换一张
取 消