user-0 提问: 去除字符串内的空格无法正常运行

回复:
user: user-0
content: 引用 6 楼 qq423399099 的回复:那是因为你的head指针的next是指向NULL的 你没法使得(*list)->next == tmp 完美解决了，非常感谢

user: user-1
content: 你需要先记录res的首地址，否则return回去的是已经指向字符串末尾的位置，所以打印出来的是空白  static char * rmSpace(const char * str) { 	int spaceCnt = 0; 	const char * head = str; 	while ((*str) != '\0') { 		if (isspace(*str)) 			spaceCnt++; 		str++; 	} 	str = head; 	int resLen = strlen(str) - spaceCnt + 1; 	char * res = (char *)malloc(sizeof(char)* resLen); 	char *res_head = res; 	memset(res, 0, resLen); 	while (*str != '\0') { 		if (*str != ' ') { 			*res = *str; 			res++; 		} 		str++; 	} 	return res_head; }

user: user-1
content: 那是因为你的head指针的next是指向NULL的 你没法使得(*list)->next == tmp

user: user-0
content: 引用 3 楼 qq423399099 的回复:你原来链表连接newNode的两句左值和右值反了  void add2head(linkedlist * list, int data) { 	linkedlist tmp = *list; 	linkedlist newNode = (linkedlist)malloc(sizeof(node)); 	(*list)->prior = newNode; //第一处！！！！ 	newNode->next = *list; 	newNode->data = data; 	while ((*list)->next != tmp) { 		*list = (*list)->next; 	} 	newNode->prior = *list; 	(*list)->next = newNode;//第二处！！！ 	*list = newNode; }   刚刚测试了一下还是不行，内存访问冲突  这是全部代码  #include <stdio.h> #include <stdlib.h>  typedef struct node{ 	int data; 	struct node * next; 	struct node * prior; }node;  typedef struct node * linkedlist;  linkedlist init(int data) { 	linkedlist  newNode = (linkedlist)malloc(sizeof(node)); 	newNode->data = data; 	newNode->next = NULL; 	newNode->prior = NULL; 	return newNode; }  void add2head(linkedlist * list, int data) { 	linkedlist tmp = *list; 	linkedlist newNode = (linkedlist)malloc(sizeof(node)); 	newNode->next = *list; 	(*list)->prior = newNode; 	newNode->data = data; 	while ((*list)->next != tmp) { 		*list = (*list)->next; 	} 	newNode->prior = *list; 	(*list)->next = newNode; 	*list = newNode; }   int main(void) { 	linkedlist head = init(123); 	add2head(&head, 7); 	add2head(&head, 9); 	system("pause"); 	return 0; }

user: user-0
content: 引用 3 楼 qq423399099 的回复:你原来链表连接newNode的两句左值和右值反了  void add2head(linkedlist * list, int data) { 	linkedlist tmp = *list; 	linkedlist newNode = (linkedlist)malloc(sizeof(node)); 	(*list)->prior = newNode; //第一处！！！！ 	newNode->next = *list; 	newNode->data = data; 	while ((*list)->next != tmp) { 		*list = (*list)->next; 	} 	newNode->prior = *list; 	(*list)->next = newNode;//第二处！！！ 	*list = newNode; }   刚测试了

user: user-1
content: 你原来链表连接newNode的两句左值和右值反了  void add2head(linkedlist * list, int data) { 	linkedlist tmp = *list; 	linkedlist newNode = (linkedlist)malloc(sizeof(node)); 	(*list)->prior = newNode; //第一处！！！！ 	newNode->next = *list; 	newNode->data = data; 	while ((*list)->next != tmp) { 		*list = (*list)->next; 	} 	newNode->prior = *list; 	(*list)->next = newNode;//第二处！！！ 	*list = newNode; }

user: user-0
content: 引用 1 楼 qq423399099 的回复:你需要先记录res的首地址，否则return回去的是已经指向字符串末尾的位置，所以打印出来的是空白  static char * rmSpace(const char * str) { 	int spaceCnt = 0; 	const char * head = str; 	while ((*str) != '\0') { 		if (isspace(*str)) 			spaceCnt++; 		str++; 	} 	str = head; 	int resLen = strlen(str) - spaceCnt + 1; 	char * res = (char *)malloc(sizeof(char)* resLen); 	char *res_head = res; 	memset(res, 0, resLen); 	while (*str != '\0') { 		if (*str != ' ') { 			*res = *str; 			res++; 		} 		str++; 	} 	return res_head; }  大神又是你 那我顺便再问一个关于双向链表的问题  void add2head(linkedlist * list, int data) { 	linkedlist tmp = *list; 	linkedlist newNode = (linkedlist)malloc(sizeof(node)); 	newNode = (*list)->prior; 	newNode->next = *list; 	newNode->data = data; 	while ((*list)->next != tmp) { 		*list = (*list)->next; 	} 	newNode->prior = *list; 	newNode = (*list)->next; 	*list = newNode; }  我的思路是创建一个新节点，然后这个新节点next指向已有链表的第一个节点，这个新节点的prior指向已有节点的最后一个，但是为什么还是无法运行