static char * rmSpace(const char * str) { int spaceCnt = 0; 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); memset(res, 0, resLen); while (*str!="\0") { if (*str != " ") { *res = *str; res++; } str++; } return res; }
今天写一个RPN计算器,在处理字符串的时候就遇到问题了,求指导
解决方案
44
你原来链表连接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; }