我们的善良将助长一个孩子不劳而获的懒惰心理
回复 11楼 我只是个学生
不需要另外用缓冲区的
#include <stdio.h> #include <stdlib.h> #include <conio.h> void Pause(void); size_t DeleteChar(char* str, char ch); int main(void) { char str[] = "123123123"; printf_s("Deleted char count is %u, then string is: %s", DeleteChar(str, '3'), str); Pause(); return EXIT_SUCCESS; } void Pause(void) { printf_s("\nPress any key to continue..."); _getch(); } size_t DeleteChar(char* str, char ch) { size_t count = 0; char* p = str; while (*str != '\0') { if (*str != ch) { *p++ = *str; } else { ++count; } ++str; } *p = '\0'; return count; }