第16周项目2-去除句子中第一个单词前的空格(指针作形参)
2014-12-15 12:51
316 查看
问题及代码:
运行结果:
知识点总结:
去除句子中第一个单词前的空格(指针作形参)。
学习心得:
还是自定义函数不好写啊啊啊!
我真是太不熟练了!
↖(^ω^)↗加油加油~
/* *Copyright (c)2014,烟台大学计算机与控制工程学院 *All rights reserved. *文件名称:num.cpp *作 者:单昕昕 *完成日期:2014年12月15日 *版 本 号:v1.0 * *问题描述:去除句子中第一个单词前的空格。 *程序输入:无。 *程序输出:去除句子中第一个单词前的空格后的句子。 */ #include <iostream> using namespace std; char *prim(char *str); int main() { char s[100]=" What hurts more, the pain of hard work, or the pain of regret? "; cout<<"/"<<s<<endl; cout<<"去除第一个空格后:"<<endl; cout<<"/"<<prim(s); return 0; } char *prim(char *str) { char *p=str,*q=str; if(*q==' ') q++; while(*q!='\0') *p++=*q++; *p='\0'; return (str); } #include <iostream> using namespace std; void ptrim(char *str); int main() { char s[100]=" What hurts more, the pain of hard work, or the pain of regret? /"; cout<<"/"<<s<<endl; cout<<"去除第一个空格后:"<<endl; ptrim(s); cout<<"/"<<s<<endl; return 0; } void ptrim(char *str) { char *p=str,*q=str; if(*q==' ') q++; while(*q!='\0') *p++=*q++; *p='\0'; }
运行结果:
知识点总结:
去除句子中第一个单词前的空格(指针作形参)。
学习心得:
还是自定义函数不好写啊啊啊!
我真是太不熟练了!
↖(^ω^)↗加油加油~
相关文章推荐
- 第16周项目2.5 去除句子中第一个单词的空格,返回处理后的字符串 用指针做形参
- 第十六周 项目二:用指针玩字符串(2.5.1:去除句子中第一个单词前的空格(用指针作形参))
- 第十六周 项目二--用指针玩字符串(2.5去除句子中第一个单词前的空格并返回--指针作形参)
- 第16周 项目2-用指针作做参数,去除句子中第一个单词前的空格
- 第十六周项目二用指针玩字符串任务五:去除句子中第一个单词前的空格,返回去除了空格的字符串(用指针作形参)
- 第十六周项目2-用指针玩字符串(任务五:去除句子中第一个单词前的空格)
- 第十六周项目2-用指针玩字符串(任务五:去除句子中第一个单词前的空格)
- 第16周项目2--用指针玩字符串(去除第一个单词前的空格)
- 第16周项目2-去除句子中所有的空格(指针作形参)
- 第十六周项目二——用指针玩字符串(5.去除句子第一个单词前的空格)
- 第十六周项目二:用指针玩字符串(5) :去除句子中第一个单词前的空格
- 第十六周项目二 用指针玩转字符串-去除第一个单词前空格
- 第16周 项目2-用指针作做参数,去除句子中多余的空格
- 第16周项目2--用指针玩字符串(去除句子中所有多余的空格)
- 第16周项目2去除第一个单词前的空格
- 第十六周项目二用指针玩字符串任务六:去除句子中所有多余的空格(用指针作形参)
- 第十六周项目2-5:去除句子中第一个单词前的空格
- 第16周项目2-去除第一个单词前空格
- 第十六周 项目二:用指针玩字符串(2.6.1:去除句子中多余的空格(用指针作形参))
- 第16周项目2.4 统计句子str中单词的个数 用指针做形参