#include "stdafx.h"
#include
int main()
{
char str[80]="\0",resultStr[80]="\0";
int cursor=0;
printf("请输入字符串:");
scanf("%s",str);
char *tempStr = str;
while (*tempStr != '\0')
{
char ch = *tempStr;
if ((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
{
resultStr[cursor] = ch;
cursor++;
}
tempStr++;
}
printf("输入字符为:%s\n输出字符为:%s\n",str,resultStr);
system("pause");
return 0;
}
那就循环判断 利用 isalpha 或者 判断在不在az 和AZ之间 可以再定义一个字符数组 将符合情况的存到新数组里面
#include
#include
using namespace std;
void func(string &in, string &out)
{
for(int i = 0; i < in.length(); ++i)
{
if((in[i] >= 'A' && in[i] <= 'Z') || (in[i] >= 'a' && in[i] <= 'z'))
out.append(in[i]);
}
}
int main()
{
string in, out;
cout<<"Input string: ";
cin>>in;
func(in, out);
cout<<"Result: "<
}
int i, j = 0;
char *Input[81];
char *Output[81];
cout << "Input a string: ";
cin >> Input;
for (i=0; i
if (isalpha(Input[i]))
Output[j++] = Input[i];
}
cout << "New String: " << Output << endl;
把你的书翻到附录部分,有个ascii码表,对吧,根据16进制判断就可以了