Re: problem with toupper()
Quote:
Originally Posted by
FenixRising
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.
Quote:
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.
Quote:
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.
Quote:
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? :)
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.
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:wave: