开发者

c strcpy copy to array of string

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜