User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 370,611 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,048 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser:
Views: 6135 | Replies: 5
Reply
Join Date: Dec 2006
Posts: 1
Reputation: vijayr_singh is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
vijayr_singh vijayr_singh is offline Offline
Newbie Poster

possible combination of a string

  #1  
Dec 13th, 2006
Hi friends...

I need to write a program in C which will print all the combinations of a string with non-repeating characters. Example: “Say” will have the following: S, a,y, Sa, Sy, aS,Sy, yS, ya, aSy,Sya,ySa and so on. The string length is not known. The string will be a command line argument to the program.


The code that i have goes below but its not giving me the desired output. the output that i m getting from this program is like

#############OUTPUT##################
Enter the string : say

sya
ysa
yas
ays
asy
say
##################################

#############DESIRED OUTPUT##################
Enter the string : say

s
a
y
sa
sy
as
ys
ay
ya
sya
ysa
yas
ays
asy
say
###########################################


###########PROGRAM################
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<alloc.h>
  4. #include<conio.h>
  5.  
  6.  
  7. void swap(char*,int);
  8. void gotoloop(char*,int);
  9.  
  10. void main()
  11. {
  12. char *ch;
  13. int i,j,k,l;
  14. ch=(char*)malloc(20);
  15. //clrscr();
  16. printf("Enter the string\n");
  17. gets(ch);
  18.  
  19. l=strlen(ch);
  20. gotoloop(ch,l);
  21.  
  22. return;
  23. }
  24.  
  25. void gotoloop(char *ch,int l)
  26. {
  27. int i,k;
  28. k=l;
  29.  
  30. if(l<=1)
  31. return;
  32.  
  33.  
  34. for(i=0;i<k;i++)
  35. {
  36. swap(ch,k);
  37. l--;
  38. gotoloop(ch,l);
  39. l++;
  40. if(k==2)
  41. printf("\n%s ",ch);
  42. }
  43.  
  44. }
  45.  
  46.  
  47. void swap(char *ch,int r)
  48.  
  49. {
  50. char c;
  51. int i;
  52.  
  53. c=ch[r-1];
  54. for(i=r-1;i>0;i--)
  55. ch[i]=ch[i-1];
  56. ch[0]=c;
  57. }


This is not like a normal permutation of string.

Can anyone help me on this ASAP.

Thanks in advance
Last edited by ~s.o.s~ : Dec 13th, 2006 at 10:44 am. Reason: Added code tags learn to use them yourself.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Dec 2005
Posts: 2,998
Reputation: Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of Salem has much to be proud of 
Rep Power: 18
Solved Threads: 327
Colleague
Salem's Avatar
Salem Salem is offline Offline
void main'ers are DOOMed

Re: possible combination of a string

  #2  
Dec 13th, 2006
Wow - a full house of forums I've seen the same post on.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
Reply With Quote  
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,871
Reputation: cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice cscgal is just really nice 
Rep Power: 32
Solved Threads: 107
Admin
Staff Writer
cscgal's Avatar
cscgal cscgal is offline Offline
The Queen of DaniWeb

Re: possible combination of a string

  #3  
Dec 13th, 2006
Huh? Whatcha mean?
Reply With Quote  
Join Date: Sep 2004
Posts: 5,983
Reputation: Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold 
Rep Power: 24
Solved Threads: 398
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: possible combination of a string

  #4  
Dec 13th, 2006
>Huh? Whatcha mean?
He means that this question has been spammed on multiple website forums, such as Daniweb, cprogramming, etc...
Member of: Beautiful Code Club.
Reply With Quote  
Join Date: Aug 2005
Posts: 4,588
Reputation: iamthwee is a jewel in the rough iamthwee is a jewel in the rough iamthwee is a jewel in the rough iamthwee is a jewel in the rough 
Rep Power: 15
Solved Threads: 290
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Industrious Poster

Re: possible combination of a string

  #5  
Dec 13th, 2006
Originally Posted by Narue View Post
>Huh? Whatcha mean?
He means that this question has been spammed on multiple website forums, such as Daniweb, cprogramming, etc...


It could also be interpretated that Salem has so much free time on his hands he can afford to join every c forum in existence. Although he does spend a lot of time on times.co.uk website. How he can juggle the two I don't know. He he.
Last edited by iamthwee : Dec 13th, 2006 at 5:04 pm.
Member of: F-ugly code club

Join today don't delay!
Reply With Quote  
Join Date: Sep 2004
Posts: 5,983
Reputation: Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold Narue is a splendid one to behold 
Rep Power: 24
Solved Threads: 398
Super Moderator
Narue's Avatar
Narue Narue is offline Offline
Expert Meanie

Re: possible combination of a string

  #6  
Dec 13th, 2006
>It could also be interpretated that Salem has so much free time on his
>hands he can afford to join every c forum in existence.
Please. Everyone knows that Salem is a bot.
Member of: Beautiful Code Club.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 6:43 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC