/*
* Copyright (c) 2014,烟台大学计算机学院
* All right reserved.
*文件名:sixteen week 2.1app
* 作者:柴银平
* 完成时间:2014年12月15日
* 版本号:v1.0
*
* 问题描述:用指针做形式参数。
*程序输入:
*程序输出:输出连接后的字符串。
*/
#include <iostream>
using namespace std;
char *pdelchar(char *str,const char c);
int main()
{
char s1[50]="Hello world. ";
char s2[50]="Good morning. ";
char s3[50]="vegetable bird! ";
cout<<"去除后:"<<pdelchar(s1,'o')<<endl;
cout<<"去除后:"<<pdelchar(s2,'i')<<endl;
cout<<"去除后:"<<pdelchar(s3,'b')<<endl;
return 0;
}
char* pdelchar(char *str, const char c)
{
char *p=str,*q=str;
for(;*q!='\0';q++)
{
if(*q!=c)
*p++=*q;
}
*p='\0';
return str;
}
学习心得:
这个我是看的贺老师的,并且看了相当一会儿才懂得,唉。。。