CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 18 of 18
  1. #16
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: problem with toupper()

    Quote Originally Posted by FenixRising View Post
    I have looked at the documentation and have changed my program. I am assuming that cstr is a pointer and that pointer arithmetic should work. But, I still have errors.
    You still don't get the idea. You have to refer to documentation in every case when you face a problem.


    Error 1 error C4996: 'strcpy': This function or variable may be unsafe. Consider using strcpy_s instead. - Which include file is strcpy_s in?
    As long as you intend to just output the result of toupper, you never need this extra copy. Iteration along the original string, STL or plain C, whatever, will do for you.

    Error 2 error C2664: 'int toupper(int)' : cannot convert parameter 1 from 'const char *' to 'int' 35 1
    Another lesson: Learn to understand compiler messages. This one literally hints you on type incompatibility. The function wants input of int, but you provide pointer to char. Dereferencing the pointer might do the trick. Or using array-style access to string chars would work even better.

    The article toupper provides some sample you have to think over.

    cout << toupper(cstr + i);
    Another unpleasant surprise waits yet behind the corner. toupper returns int, so you're going to have a chain of char decimal codes here as the console print out. What would be your next move?
    Best regards,
    Igor

  2. #17
    Join Date
    Apr 2013
    Posts
    42

    Re: problem with toupper()

    Hi 2kaud,
    The book that I am using is C++ Primer Plus by Stephen Parata. I am currently on page 445 of 1,334 pages. As far as the exercise goes, it really is an exercise is passing parameters by reference and the toupper function as a side bar. He really doesn't go into the cctype character functions. I didn't know about the online C++ library. So, now I have a reference to go to for C++.

    The solution works. Thanks to everyone for their help. I learned a lot.

  3. #18
    2kaud's Avatar
    2kaud is offline Super Moderator Power Poster
    Join Date
    Dec 2012
    Location
    England
    Posts
    7,824

    Re: problem with toupper()

    As you are learning from the book, how do you rate it? I've got an old 1998 edition of this and at the time I thought it was quite good.

    Learning from a book is not the same as having a teacher explain things. There are several free c++ tutorials on youtube which may be of interest. Search for c++ tutorial. If you're interested, there are also interviews with c++ industry experts - eg Bjarne Strousrup (who invented the c++ language), Scott Meyers etc.

    Happy coding
    All advice is offered in good faith only. All my code is tested (unless stated explicitly otherwise) with the latest version of Microsoft Visual Studio (using the supported features of the latest standard) and is offered as examples only - not as production quality. I cannot offer advice regarding any other c/c++ compiler/IDE or incompatibilities with VS. You are ultimately responsible for the effects of your programs and the integrity of the machines they run on. Anything I post, code snippets, advice, etc is licensed as Public Domain https://creativecommons.org/publicdomain/zero/1.0/ and can be used without reference or acknowledgement. Also note that I only provide advice and guidance via the forums - and not via private messages!

    C++23 Compiler: Microsoft VS2022 (17.6.5)

Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured