17周项目二,2,(指针做形参)

来源:互联网 发布:手机怎样设置网络快 编辑:程序博客网 时间:2024/05/17 21:40
上机内容:C++程序的编写和运行
上机目的:掌握简单C++程序的编辑、编译、连接和运行的一般过程
我的程序:
/*Copyright (c) 2013, 烟台大学计算机学院* All rights reserved.* 作    者:赵玲玲* 完成日期:2013 年 12 月 18 日* 版 本 号:v1.0* 输入描述:无* 问题描述:去除字符串中的空格并保留在原字符串中(指针做形参)* 程序输出:略* 问题分析:如果遇到空格,后一个字符赋值给空格所在位置* 算法设计:略*/#include <iostream>#include <string.h>using namespace std;void pdelchar(char *str,const char c);   //指针做形参int main(){    char s1[50]="Hello world. ";    char s2[50]="Good morning! ";    pdelchar(s1,' ');    pdelchar(s2,' ');    cout<<"去除空格后:"<<s1<<'\t'<<s2<<endl;    return 0;}void pdelchar(char *str,const char c){    int i,n=0;    n=strlen(str);    for(i=0; i<n; i++)    {        if(*(str+i)==c)                  //将str[i]改为(*str+i)即可        {            *(str+i)=*(str+i+1);        }    }}


运行结果:
心得体会: 略
知识点总结:略
0 0
原创粉丝点击