#include <iostream>
#include <string>
using namespace std;
int del_blanks(char* str)
{
int count = 0;
int count1 = 0;
if (str == nullptr) {
return 0;
}
int res = 0;
char* l = str;
char* r = str;
while (*(l + res) != '\0') {
while (*r != '\0' && *r == ' ') {
r++; // 遇到了空格 右指针 提前跳过
res++;
count++;
cout << count << endl;
}
*l = *r;
l++;
r++;
count1++;
cout << count1 << endl;
}
*l = '\0';
cout << str << endl;
return res;
}
int main() {
string a = "I am a worker";
//cout << a << endl;
//del_blanks(const_cast<char*>(a.c_str()));
char b[] = "I am a worker";
cout << del_blanks(b) << endl;
//test(a);
return 0;
}