Q BgQuestion:

      
Scholar
Karma Points: 235
Respect (89%):
posted by  John786 on 11/1/2009 5:16:50 PM  |  status: Closed  |  Earned Karma: 235

C++ Function (urgent)

Course Textbook Chapter Problem Needs by
N/A N/A N/A N/A 11/4/2009 at 4:00:00 PM
Question Details:
Let f be the following C++ function:

void f (char *p)
{
     char *q = p;

     while (*q)
q++;
     while (p < q) {
char ch = *p;
*p++ = *--q
*q = ch;
      }
}


Assume that the argument to f is C-style (null-terminated) string.

A) What modification does f perform to the string that is passed to it?
B) Explain how f works.

AAnswers:

Answer Question Ask for clarification
Scholar
Karma Points: 235
posted by John786 on 11/2/2009 9:44:35 PM  |  status: Live
Asker's Rating: N/A-Posted by Person Asking Question   
Response Details:
Please Help Someone 
Oracle
Karma Points: 31,880
posted by rapunzel on 11/2/2009 10:03:14 PM  |  status: Live
Asker's Rating: Lifesaver   
Response Details:
please rate - thanks

the characters in the string are reveres
if enter the function with abcd
exit with
dcba

starts at the beginning of the string and q steps through the string until it gets to the end
starting with the first and  last characters in the string
it  swaps the end characters  moves in one character on each side swaps them keeps moving in and swapping 1characters until the 2 pointers cross each others paths

(hope this makes sense)

Note to all members 1. Please 1 question per post 2. Show respect to your fellow members by rating all answers. 3. When rating remember that the first answer is not necessarily the best answer. 4. When answering questions, explain what you are doing, so that the asker will learn, don't just give a meaningless number. 5. Your answers should be your work. Don't copy from another member, this is Karma abuse and possible disciplinary actions against you. and GOOD LUCK to you all!!
Answer Question Ask for clarificarion

Join Cramster's Community

Cramster.com brings together students, educators and subject enthusiasts in an online study community. With around-the-clock expert help and a community of over 100,000 knowledgeable members, you can find the help you need, whenever you need it. Join for free today » How Cramster is different from tutoring »