为了方便起见,假设原来的字符串字母都是小写(其实有大写再转换下就是,懒得了)
为了实现上述功能,这里有个比较蠢的方法
#include <iostream>
#include <cstring>
#include <fstream>
using namespace std;
int main()
{
ifstream in("f");
if (!in)
{cerr << "open file error";
return -1;
}
char s[80] = {0},*p,*new_s;
int cnt = 0;in.getline(s,81,'\n');
in.close();
p = s;while (*p!='\0')
{
if (!('a'<=*p && *p<='z'))
++p;
else {++cnt;++p;}
}
p = s;
s_new = new char [cnt+1];
while (*p!='\0')
{
if ('a'<=*p && *p <='z')
strncat(s_new,p,1);
++p;
}
}