![]() |
|
#1
|
|||
|
|||
Need help with stringsI am a newbie at c++ programing, but we are using MS .Net version of C++. Anyway, I would appreciate it if someone could help give some tips on how to capitalize a whole string of array (Not just the first char of the word). We need to make a console that outputs 25 lines of array which i did with:
CPP / C++ / C Code:
Thanks in advance. ![]() |
|
#2
|
|||
|
|||
Re: Need help with stringsQuote:
Much of your code won't compile on my C++ compiler (GNU gcc), and you didn't ask for advice in general, so I'll just show a couple of ways (three, actually) using standard C++ to translate a string to upper case. Pick any of the three that you like and try it in your program. CPP / C++ / C Code:
My output: Code:
Loop 1 shows use of iterators. Loop 2 shows use array index[] notation. This is valid and is standard C++, but, no bounds checking is done. For this example, that's no problem since the loop obviously doesn't go outside the string. (Of the three methods that I show, this is the only that is available to C programmers.) The transform function is preferred by many experienced C++ programmers, since the function itself goes through the string and applies tolower() to each element. And, I presume, that the code would have been optimized as much as possible by the library function. The complicated-looking type casting on "toupper" is required, since there are actually a couple of toupper functions in the standard C++ library. In fact, in some compiler libraries the toupper() that we want has been implemented as a macro, so that no type information is associated by its name. (So just writing the identifier "toupper" by itself as the fourth argument to the transform() function would not give enough information to the compiler to let it know what function we need here.) We use the cast to tell the compiler that the use of "toupper" in this instance (the name "toupper" by itself) is supposed to be a pointer to an int function whose agument is an int. (Therefore the compiler picks the int toupper(int) function that is the same as the C standard library toupper() function.) Regards, Dave Last edited by davekw7x : 23-Apr-2006 at 01:07.
|
|
#3
|
|||
|
|||
Re: Need help with stringsokay i must be invoking it wrong then. My current codes are:
CPP / C++ / C Code:
Now i know the findReplace function doesnt do its job, but it all runs without error. Same goes for the Capitalization of the array string. I am pretty sure my invoking is all wrong for these funtions. All the other invokation works because i had help with those from an instructor, but I cant seem to understand how to invoke these properly. There is just too many different ways to do invoking that i do not understand at all. |
|
#4
|
|||
|
|||
Re: Need help with stringsQuote:
Since I have no way of compiling your program there's not much I can to about overall functionality, however, there is a way for you to get to the bottom of things yourself. (It's faster, I claim, and more edifying than posting a request for help and waiting for a helpful response). My suggestion when implementing a new function is to create a test program consisting of a main() function that does nothing but invoke the new function. Test it until you think it is correct. Then try to integrate into your real program. If the test program seems to work OK, but the function doesn't seem to be doing its job in the real program, then put some print statements before the function call and inside the function to see what the program is seeing. Make the program tell you what it is working on and what it is doing. For example: CPP / C++ / C Code:
Regards, Dave |
|
#5
|
|||
|
|||
Re: Need help with stringsThanx Dave. Your the best, I have been doin little tests in its own main as an independant cpp file to make it work first, but i just couldnt invoke it properly into the larger project. But alast i got it working. I just missed a simple &ersign to the other function so i can draw the current values within the userText variable. Anyway, thanks a bunch, now all i just need to work on the find and replace function. Which i also am not sure of how it works and all, but its always better to try till you can think no more before asking for more help eh
|
Recent GIDBlog
US Elections and the ?Voter?s Responsibility? by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Strings tripping me up once more | Elsydeon | C++ Forum | 5 | 04-Dec-2005 18:41 |
| need help - questions about strings | Benayoun | C Programming Language | 6 | 24-Jan-2005 03:15 |
| array of pointers to strings | mirizar | C++ Forum | 5 | 21-Jan-2005 11:24 |
| C++ style strings and STL | dexter | C++ Forum | 14 | 04-Jan-2005 08:46 |
| I am reviewing Arrays and need help converting some strings to arrays | jenmaz | C Programming Language | 22 | 23-Nov-2004 00:26 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The