不知道别人怎么看``应该是自己的道行不够吧..!拿C处理字符串``着实太恶心啊...!
void stringdelete(char *str, const char *sub) { while (NULL != (str = strstr(str, sub))) { memmove(str, str + strlen(sub), strlen(str + strlen(sub)) + 1); } } int main()//拿C来处理字符串``这不是要狗命么 - -! { char ch[50], lch[50]{0}, maxch[50]{0}; std::cout << "来个串儿" << std::endl; std::cin.getline(ch, size_t(ch)); //int len = strlen(ch); for(int i = 0; i < strlen(ch); i++) { if(0x20 == ch[i]) { if(strlen(lch) < i+1) { strncpy_s(lch, ch, i+1); stringdelete(ch, lch); strncpy_s(maxch, lch, i+1); i = 0; } else { strncpy_s(lch, ch, i+1); stringdelete(ch, lch); i = 0; } if(NULL == std::strstr(ch, " ")) //判断剩下的字符串是否有空格 { if(strlen(lch)-1 < strlen(ch)) strcpy_s(maxch, ch); else strcpy_s(maxch, lch); continue; } } } std::cout << "最长的那个是:" << maxch << std::endl; std::cin.get(); return 0; }
代码很垃圾``不喜勿喷``欢迎大佬提点
标签:sub,..,char,抠出,str,字符串,strlen From: https://www.cnblogs.com/Emotionless/p/17777352.html