/*
* Copyright (c) 2014,烟台大学计算机学院
* All right reserved.
* 作者:曹莉萍
* 文件:demo.cpp
* 完成时间:2014年12月16日
* 版本号: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! ";
pdelchar(s1,' ');
cout<<"去除空格后:"<<s1<<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++;
}
}
*p='\0';
return str;
}
运行结果
/*
* Copyright (c) 2014,烟台大学计算机学院
* All right reserved.
* 作者:曹莉萍
* 文件:demo.cpp
* 完成时间:2014年12月16日
* 版本号:v1.0
*/
#include <iostream>
using namespace std;
int pstrlen(char *str);
int main()
{
int n;
char s1[50]="Hello world. ";
n=pstrlen(s1);
cout<<"\""<<s1<<"\""<<"的长度为"<<n<<endl;
return 0;
}
int pstrlen(char *str)
{
char *p=str;
int i=0;
for(;*p!='\0';p++)
i++;
return i;
}
运行结果