我有一个这样的字符串数组:
char **strArray;
这个数组是满的,我可以用这个方法打印它的内容:
while(*strArray){
printf("%s\n",*(strArray++));
}
这工作正常。但是当我使用这个时:
while(*strArray){
process(*(strArray++));
}
我取出数组中第二个字符串的内存错误。它为第一个字符串运行,但在第二个字符串时失败。
感谢帮助!
处理方法如下:
process(char *line)
{
char *server_id,*delimiter,*outputMessage,*capacity_str;
int capacity;
delimiter = " ";
strtok(line,delimiter);
server_id = (char *)strtok(NULL,delimiter);
capacity_str = (char *)strtok(NULL,delimiter);
capacity = atoi(capacity_str);
curr_server = (server *)malloc(sizeof(server));
curr_server->server_id = server_id;
curr_server->capacity = capacity;
curr_server->full_capacity = 0;
curr_server->next = head_server;
head_server = curr_server;
strcpy(outputMessage , "server added ");
strcat(outputMessage,server_id);
strcat(outputMessage,"~");
strcat(outputMessage,capacity_str);
strcat(outputMessage,"\n");
writeOutput(outputMessage);
}