Hi,I want to reverse a string using single pointer.How to do this.Just give me an idea
Hi,I want to reverse a string using single pointer.How to do this.Just give me an idea
You could swap the first and last character of your string until you reach the middle. This will only use chars.
Or do you mean you want to use one additionnal pointer other than the one for the string (in which case, it would be much easier) ?
Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction
If you can use an index you can swap the items starting at 0 and length-index-1 until half the string is reached
Code:int index = 0; int length = strlen(ptr); // for half the string length swap(ptr[index], ptr[length - index - 1]); index++;