首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

邦小弟我写一函数

2012-03-03 
邦我写一函数函数如下:getstr(char*str)要求在main中调用此函数时str中的字符串只有字母.谢谢.你比如:mai

邦我写一函数
函数如下:
getstr(char*   str);要求在main中调用此函数时str中的字符串只有字母.谢谢.你比如:main中str= "loveyou12345lovethen ";   getstr(str)后str变要loveyoulovethen.

[解决办法]
作业 题?
应该不难的,楼主自己动手吧
[解决办法]
#include <iostream>
using namespace std;

void getstr(char*c)
{
char* t = c;
char d;
while(d=*t++)
{
if(d> = '0 ' && d <= '9 ')
continue;
*c++=d;
}
*c=0;
}
int main()
{
char c[20] = "aaa123bb456dd ";
getstr(c);
cout < <c < <endl;
system( "pause ");
return 0;
}

[解决办法]
#include <stdio.h>
#include <string.h>


void getstr(char *c)
{
char *p = c;
for (int i = 0; *c++ != '\0 '; i++)
{
if ((*c < 'z ' && *c > 'a ') || (*c < 'Z ' && *c > 'A '))
*p++ = *c;
}
*p = '\0 ';
}

void main()
{
char str[] = "asdjkDfFFDD23234SS ";

getstr(str);

printf(str);

}
难道真是作业....自己好好做嘛

热点排行