第16周项目2--用指针玩字符串(统计字符串长度)
来源:互联网 发布:淘宝衣服模特韩国 编辑:程序博客网 时间:2024/06/07 02:58
/* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作 者:刘畅 * 完成日期:2014 年 12 月 11 日 * 版 本 号:v1.0 * * 问题描述:用指针作形参,其核心是实现int (char str[])函数。; * 输入描述:无需输入; * 程序输出:输出要求输出的。
(1)用数组名作行参;
#include <iostream>using namespace std;int astrlen(char str[]);int main(){ char s1[50]="Hello world. "; char s2[50]="Good morning. "; char s3[50]="vagetable bird! "; cout<<astrlen(s1)<<endl; cout<<astrlen(s2)<<endl; cout<<astrlen(s3)<<endl; return 0;}int astrlen(char str[]){ int i=0,m=0; while (str[i]!='\0') { m++; i++; } str[i]='\0'; return m;}(2)用指针作行参;
#include <iostream>using namespace std;int astrlen(char *str);int main(){ char s1[50]="Hello world. "; char s2[50]="Good morning. "; char s3[50]="vagetable bird! "; cout<<astrlen(s1)<<endl; cout<<astrlen(s2)<<endl; cout<<astrlen(s3)<<endl; return 0;}int astrlen(char *str){ int i=0,m=0; while (*(str+i)!='\0') { m++; i++; } *(str+i)='\0'; return m;}
运行结果:
1 0
- 第16周项目2--用指针玩字符串(统计字符串长度)
- 第16周项目2-用指针玩转字符串-(3)求字符串长度
- 第16周项目2-用指针玩字符串(3)字符串长度
- 第16周项目2--用指针玩字符串(统计字符串中单词个数)
- 第16周项目2-用指针玩字符串(统计单词个数,用指针作形参)
- 第16周项目2-用指针玩字符串(统计单词个数)
- 第16周项目2-用指针玩转字符串-(4)统计单词个数
- 第十六周 项目二 用指针玩转字符串(统计字符长度)
- C++第17周项目2——用指针玩字符串(3)求字符串长度
- 第16周项目2 用指针玩字符串2
- 第16周项目2(4)-用指针玩字符串
- 第16周项目2(5)-用指针玩字符串
- 第16周项目2(6)-用指针玩字符串
- 第16周项目2(7)-用指针玩字符串
- 第16周项目2-用指针玩字符串
- 第16周【项目 2-用指针玩字符串】①
- 第16周【项目 2-用指针玩字符串】②
- 第16周 项目2-用指针玩字符串(1)
- Notes on Conjugate Gradient Method
- 【HEVC学习与研究】3、HEVC概览(3)
- Unity3D学习之(基础查询和数据库连接)
- C# 使用技巧
- Spring MVC 的的异常处理(跳转页面和返回json双模式)
- 第16周项目2--用指针玩字符串(统计字符串长度)
- 2014 12 11
- 【HEVC学习与研究】4、关于IEEE TCSVT的HEVC Special Section
- 2014年苹果ios开发者证书申请及xcode5应用上线发布
- Python+Django+Eclipse 在Windows下快速开发自己的网站
- SpringMVC学习笔记--Spring Tag
- 【HEVC学习与研究】5.HEVC综述(第一部分)
- 矩阵快速幂
- 【HEVC学习与研究】6.HEVC综述(第二部分)