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

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

 
0
  #1
Jan 1st, 2009
help.. i dont know how to sort strings.. for example..

if i enter:
  1. JOKER

then the descending order of string must appear:
  1. ROKJE

i think of strcpy() ..but it i dont know what to place in the if().. here's my code..

  1. #include<iostream.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<stdio.h>
  5. void main()
  6. {
  7. clrscr();
  8. char a[100],temp[100];
  9. cout<<"Enter string: ";
  10. gets(a);
  11. cout<<"\nThe reverse of the string entered is: ";
  12. for(int i=(strlen(a)-1);i>=0;i--)
  13. cout<<a[i];
  14. cout<<"\n\nLETTERS IN THE STRING: ";
  15. for(int b=0;b<=(strlen(a)-1);b++)
  16. {
  17. for(int c=0;c<=(strlen(a)-2);c++)
  18. {
  19. if(strcmp(a[c],a[c+1])<0) //I DON"T THINK THIS IS RIGHT
  20. {
  21. strcpy(temp,a[c]);
  22. strcpy(a[c],a[c+1]);
  23. strcpy(a[c],temp);
  24. }
  25. }
  26. }
  27. getch();
  28. }


how could i implement the strcpy or the strcmp in my code??
Reply With Quote