可能重复: Why do I get a segmentation fault when writing to a string? 我想在一个字符串替换词。下面是代码 char text[] = "This is a list of lists";
char *find = "list";
char* pos = NULL;
pos = strstr(text,find);
strncpy
我有一个函数可以解析一些进入的数据。我的问题是使用strncpy后,当我尝试打印它时,我得到一些垃圾。我尝试使用malloc使char数组具有确切的大小。 代码:再次 The original string is:
NEW_DATAa_PACKET
Local Data Set 16-byte Universal Key
Time Stamp (microsec): 131963950109