how to reverse a string in character array without using string functions...

Recommended Answers

All 7 Replies

One way to do it is to copy the string backwards into another character array.

thnks!
can you please help me with the code...

If you are asking me to write the code for you, the answer is no. Try to do it yourself and post the code you tried. Try it out with pencil & paper first so that you can figure out in your head what has to be done. Then use a simple example, such as some three letter word.

thnks ...i did it

#include<iostream.h>
#include<conio.h>
void main()
{
char a[100];
cout<<"Enter string";
cin.get(a,100);
cout<<"\nReversed string:";
int i,j;
i=0;
while(a!='\0')
{
i++;
}

for(j=i-1;j>=0;j--)
{
cout<<a[j];
}
getch();
}

Either you are a very very fast programmer, or you cheated and plagiarized someone else's poorly written and non-standard code.

commented: Agreed +1

i knew how to enter string was jus confused about the second for loop then i tried n it worked...

I'll give you the benefit of the doubt and assume that's true, but I'm giving you a friendly warning. You really should have said that and posted your code sooner. You would have gotten better help because the post wouldn't have looked so "givemethecodez", which is frowned upon. That's why you got this reply from AD.

Now just figure out your CODE-tags

#include <iostream>
int main() {
  std::cout << "This looks nice, and is easily readable." << std::endl;
  return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.