•
•
•
•
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
![]() |
•
•
Join Date: Dec 2006
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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################
This is not like a normal permutation of string.
Can anyone help me on this ASAP.
Thanks in advance
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################
c Syntax (Toggle Plain Text)
#include<stdio.h> #include<string.h> #include<alloc.h> #include<conio.h> void swap(char*,int); void gotoloop(char*,int); void main() { char *ch; int i,j,k,l; ch=(char*)malloc(20); //clrscr(); printf("Enter the string\n"); gets(ch); l=strlen(ch); gotoloop(ch,l); return; } void gotoloop(char *ch,int l) { int i,k; k=l; if(l<=1) return; for(i=0;i<k;i++) { swap(ch,k); l--; gotoloop(ch,l); l++; if(k==2) printf("\n%s ",ch); } } void swap(char *ch,int r) { char c; int i; c=ch[r-1]; for(i=r-1;i>0;i--) ch[i]=ch[i-1]; ch[0]=c; }
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.
•
•
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,871
Reputation:
Rep Power: 32
Solved Threads: 107
Huh? Whatcha mean?
Dani the Computer Science Gal
Do you run a computer-related website? Feature it in our niche link directory!
Do you run a computer-related website? Feature it in our niche link directory!
•
•
•
•
>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!
Join today don't delay!
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
Similar Threads
- write a program which take a string give it permutations and combination (C++)
- write a program which take a string give it permutations and combination (C++)
- take string give it all possible combination (C++)
- Conver int Array into a String (Java)
Other Threads in the C Forum
- Previous Thread: error in the program
- Next Thread: recursive backtracking



Linear Mode