Convert string to uppercase -- C ++ implementation

Source: Internet
Author: User

Although this question is very simple, it will also make a lot of mistakes. You will know it at ordinary times, but it is easy to be silly during programming, and you will not be able to get it back...

It seems that you still need to write more code .. No nonsense.

Paste the Code directly ..

# 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 ;}

My Fan error:

1: char * src = "helloworld", I directly used SRC to change the value .. It's really second...

2: At that time, index was not used, but * m_dest ++ was used, which is a second place ..

Don't let this happen... Record...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.