![]() |
|
|||||||
|
|
Thread Tools | Search this Thread | Rate Thread |
|
#1
|
|||
|
|||
Write a function name reverseCString with two formal input parametersgood morning guys,
we were tasked to write a function name reverseCString with two formal input parameters. Thes input parameters are pointers to char data. The function should not have any return value. here is the function prototype : void reverseCString( char *source, char *target ); The formal parmeter source is a pointer to the first character of the actual source C-String. The formal parameter target is a pointer to the first character of the target C-String. The charcters in the source C-String should be copied to the target C-String in reverse. we are only allowed to use the iostream header file. INPUT: program should start by reading the number of input data. Let this number be N. The program then should read N C-Strings. SAMPLE INPUT 4 heLLo THERE manny paqUIao SAMPLE OUTPUT heLLo : oLLeh THERE : EREHT manny : ynnam paqUIao: oaIUqap i have the code and it is working, i'm wondering if i follow the instruction carefully, and i want some comments to improve my code: thank guys here is the code CPP / C++ / C Code:
thanks guy, your comments are highly appreciated |
|||
|
#2
|
||||
|
||||
Re: Write a function name reverseCString with two formal input parametersThe program looks good. Possible changes:
The first while can be replaced with a single call to strlen(). All you're looking for is the length of the array. The second while can be changed to a for which also allows you to get rid of one of your variables. __________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
|
#3
|
||||
|
||||
Re: Write a function name reverseCString with two formal input parametersQuote:
WaltP may need new reading glasses: we are only allowed to use the iostream header file. Allan, You don't need the length of the source string, rather, a pointer to it will work nicely: CPP / C++ / C Code:
Output: Code:
Obviously, this code does not catch buffer overflow errors, which is "bad." However, the point of it is that you can use pointer arithmetic. It doesn't really save you any storage, but using a pointer instead of a "counter" indicates that you have an understanding of pointers, which may be helpful if scoring is involved. El Mexicana Roberto Originales |
|
#4
|
|||
|
|||
Re: Write a function name reverseCString with two formal input parametersyeah that's right,
by the way thanks for your comments i'l change my other statements to make it simple, about score, yeah it will make my score higher!! thank you guys!! |
Recent GIDBlog
Accepted for Ph.D. program by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multiple questions for C++ project | devster420 | C++ Forum | 1 | 20-Apr-2007 22:26 |
| Message Class | TransformedBG | C++ Forum | 5 | 29-Nov-2006 22:28 |
| reverse a string using recursion | varun51 | C Programming Language | 1 | 13-Oct-2006 19:31 |
| Help wit my source code compiler errors | Krandygrl00 | C++ Forum | 1 | 06-Jun-2005 09:14 |
| Reverse UTF encoded string | maaz | C++ Forum | 2 | 13-Apr-2005 13:33 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The