View Single Post
Join Date: Jan 2009
Posts: 45
Reputation: scias23 is an unknown quantity at this point 
Solved Threads: 0
scias23's Avatar
scias23 scias23 is offline Offline
Light Poster

Re: sorting characters in a string... help!!!!

 
0
  #4
Jan 1st, 2009
Originally Posted by da penguin View Post
Look, you have that #include<string.h> right? So why don't you use c++ strings? It's like
  1. string str;
  2. str = "whatever"
and it's easier.
Now this
  1.  
  2. for(int b=0;b<=(strlen(a)-1);b++)
  3. {
  4. for(int c=0;c<=(strlen(a)-2);c++)
  5. {
  6. if(strcmp(a[c],a[c+1])<0) //I DON"T THINK THIS IS RIGHT
  7. {
  8. strcpy(temp,a[c]);
  9. strcpy(a[c],a[c+1]);
  10. strcpy(a[c],temp);
  11. }
  12. }
  13. }

is a mess. You could just compare a[c] < a[c+1] cuz this are characters, not strings and they are already sorted in ASCII.

Could you please explain what the program is supposed to do?
okay, the program should sort the characters in a string in descending order.. for example.. if i cin yahoo, the program should cout yooha.. there..
Last edited by scias23; Jan 1st, 2009 at 9:04 am. Reason: for clarification
Reply With Quote