zoukankan      html  css  js  c++  java
  • 将字符串变成大写----C++实现

    虽然这个题目很简单,但是也是会范很多错误的,平时你肯定知道,但是在编程的时候就是容易犯傻,而且八匹马都拽不回来。。。

    看来还是要多写写代码。。不废话了。

    直接贴代码。。

    #include<iostream>
    #include<string>
    using namespace std;
    
    
    char* toUpperChar(char* src)
    {
    	int length=strlen(src);
    	char* m_dest=new char[length+1];
    	memset(m_dest,0,length+1);
    	memcpy(m_dest,src,length);
    	int index=0;
    	while(m_dest[index])
    	{
    		if(m_dest[index]>'a'&&m_dest[index]<'z')
    			m_dest[index]=m_dest[index]+'A'-'a';
    		index++;
    	}
    	return m_dest;
    
    	
    }
    void main()
    {
    	char* m_src="helloworld";
    	char* result=toUpperChar(m_src);
    	cout<<result<<endl;
    }
    
    


    我范的错误:

    1:char* src="helloworld",我直接用了src去改变其中的值。。真是二。。。

    2:当时没有用index,而是用*m_dest++,又是一个二的地方。。

    大家不要范这样的错误。。。记录一下。。。

  • 相关阅读:
    MySQL基本命令总结
    B+树
    5.Flask-Migrate
    Tornado入门五
    Django之数据库表的单表查询
    MySQL表完整性约束
    MysQL表相关操作
    MySQL库相关操作
    MySQL创建用户+授权+备份
    公司 邮件 翻译 培训 6 长难句
  • 原文地址:https://www.cnblogs.com/pangblog/p/3266646.html
Copyright © 2011-2022 走看看