String Processing --- Write out a function that prints out all the permutations of a string. For example, abc would give you abc, acb, bac, bca, cab, cba.

1 Answer

Answer :

void PrintPermu (char *sBegin, char* sRest) {
int iLoop;
char cTmp;
char cFLetter[1];
char *sNewBegin;
char *sCur;
int iLen;
static int iCount;
iLen = strlen(sRest);
if (iLen == 2) {
iCount++;
printf("%d: %s%s\n",iCount,sBegin,sRest);
iCount++;
printf("%d: %s%c%c\n",iCount,sBegin,sRest[1],sRest[0]); return;
} else if (iLen == 1) {
iCount++;
printf("%d: %s%s\n", iCount, sBegin, sRest); return;
} else {
// swap the first character of sRest with each of  // the remaining chars recursively call debug print sCur = (char*)malloc(iLen);
sNewBegin = (char*)malloc(iLen);
for (iLoop = 0; iLoop < iLen; iLoop ++) {
strcpy(sCur, sRest);
strcpy(sNewBegin, sBegin);
cTmp = sCur[iLoop];
sCur[iLoop] = sCur[0];
sCur[0] = cTmp;
sprintf(cFLetter, "%c", sCur[0]);
strcat(sNewBegin, cFLetter);
debugprint(sNewBegin, sCur+1);
}
}
}
void main() {
char s[255];
char sIn[255];
printf("\nEnter a string:");
scanf("%s%*c",sIn);
memset(s,0,255);
PrintPermu(s, sIn);
}

Related questions

Description : printf() Function- What is the difference between "printf(...)" and "sprintf(...)"?

Last Answer : sprintf(...) writes data to the character array whereas printf(...) writes data to the standard output device.

Description : malloc() Function- What is the difference between "calloc(...)" and "malloc(...)"?

Last Answer : 1. calloc(...) allocates a block of memory for an array of elements of a certain size. By default the block is initialized to 0. The total number of memory allocated will be (number_of_elements * ... calls malloc(...) in order to use the C+ + _set_new_mode function to set the new handler mode.

Description : "union" Data Type What is the output of the following program? Why?

Last Answer : #include main() { typedef union { int a; char b[10]; float c; } Union; Union x,y = {100}; x.a = 50; strcpy(x.b,"hello"); x.c = 21.50; printf("Union x : %d %s %f n",x.a,x.b,x.c); printf("Union y : %d %s %f n",y.a,y.b,y.c); }

Description : Linked Lists -- Can you tell me how to check whether a linked list is circular?

Last Answer : Create two pointers, and set both to the start of the list. Update each as follows: while (pointer1) { pointer1 = pointer1->next; pointer2 = pointer2->next; if (pointer2) pointer2=pointer2->next ... before pointer1, or the item before that. Either way, its either 1 or 2 jumps until they meet.

Last Answer : Size of the final executable can be reduced using dynamic linking for libraries.

Description : What is the output of printf("%d")?

Last Answer : 1. When we write printf("%d",x); this means compiler will print the value of x. But as here, there is nothing after ï ½%dï ½ so compiler will show in output window garbage value. 2. When we ... an error without the proper number and type of arguments for things like printf(...) and scanf(...).

Description : What is C language?

Last Answer : The C programming language is a standardized programming language developed in the early 1970s by Ken Thompson and Dennis Ritchie for use on the UNIX operating system. It has since spread to ... language for writing system software, though it is also used for writing applications. ...

Description : What is the output when following statement is executed ? >>>"a"+"bc" a) a b) bc c) bca d) abc

Last Answer : b) bc

Description : triangle ABC is right angled at A. AL is drawn perpendicular to BC. Prove that /_ BAL = /_ ACB -Maths 9th

Last Answer : NEED ANSWER

Description : triangle ABC is right angled at A. AL is drawn perpendicular to BC. Prove that /_ BAL = /_ ACB -Maths 9th

Last Answer : This answer was deleted by our moderators...

Description : PQRS is a square. A is a point on PS ,B is a point on PQ,C is a point on QR. ABC is a triangle inside square PQRS. Angle abc = 90° . If AP=BQ=CR then prove that angle BAC =45° -Maths 9th

Last Answer : This is the sketch of the question but its hard to answer.

Description : ABC is an isosceles triangle in which AB=AC.AD bisects exterior angles PAC and CD parallel AB.Prove that-i)angle DAC=angle BAC ii)∆BCD is a parallelogram -Maths 9th

Last Answer : AB =AC(given) Angle ABC =angle ACB (angle opposite to equal sides) Angle PAC=Angle ABC +angle ACB (Exterior angle property) Angle PAC =2 angle ACB - - - - - - (1) AD BISECTS ANGLE PAC. ANGLE ... AND AC IS TRANSVERSAL BC||AD BA||CD (GIVEN ) THEREFORE ABCD IS A PARALLEGRAM. HENCE PROVED........

Description : PQRS is a square. A is a point on PS ,B is a point on PQ,C is a point on QR. ABC is a triangle inside square PQRS. Angle abc = 90° . If AP=BQ=CR then prove that angle BAC =45° -Maths 9th

Last Answer : This is the sketch of the question but its hard to answer.

Description : ABC is an isosceles triangle in which AB=AC.AD bisects exterior angles PAC and CD parallel AB.Prove that-i)angle DAC=angle BAC ii)∆BCD is a parallelogram -Maths 9th

Last Answer : AB =AC(given) Angle ABC =angle ACB (angle opposite to equal sides) Angle PAC=Angle ABC +angle ACB (Exterior angle property) Angle PAC =2 angle ACB - - - - - - (1) AD BISECTS ANGLE PAC. ANGLE ... AND AC IS TRANSVERSAL BC||AD BA||CD (GIVEN ) THEREFORE ABCD IS A PARALLEGRAM. HENCE PROVED........

Description : In triangle ABC, angle B =35° , angle C =65° and the bisector of angle BAC meets BC in X. Arrange AX, BX and CX in descending order. -Maths 9th

Last Answer : NEED ANSWER

Description : In triangle ABC, angle B =35° , angle C =65° and the bisector of angle BAC meets BC in X. Arrange AX, BX and CX in descending order. -Maths 9th

Last Answer : This answer was deleted by our moderators...

Description : In the above `Delta ABC` ( not to scale ), OA is the angle bisector of `/_ BAC` . If `OB=OC,/_OAC=40^(@)` and `/_ ABO=20^(@)`. If `/_ OCB=(1)/(2) /_ A

Last Answer : In the above `Delta ABC` ( not to scale ), OA is the angle bisector of `/_ BAC` . If `OB=OC,/_OAC=40^(@) ... OCB=(1)/(2) /_ ACO,` then find `/_ BOC.`

Description : ABC and ADC are two right triangles with common hypotenuse AC. Prove that angle CAD = angle CAB -Maths 9th

Last Answer : Given, AC is the common hypotenuse. ∠B = ∠D = 90°. To prove, ∠CAD = ∠CBD Proof: Since, ∠ABC and ∠ADC are 90°. These angles are in the semi circle. Thus, both the triangles are lying in the semi ... D are concyclic. Thus, CD is the chord. ⇒ ∠CAD = ∠CBD (Angles in the same segment of the circle)

Description : ABC and ADC are two right triangles with common hypotenuse AC. Prove that angle CAD = angle CAB -Maths 9th

Last Answer : Given, AC is the common hypotenuse. ∠B = ∠D = 90°. To prove, ∠CAD = ∠CBD Proof: Since, ∠ABC and ∠ADC are 90°. These angles are in the semi circle. Thus, both the triangles are lying in the semi ... D are concyclic. Thus, CD is the chord. ⇒ ∠CAD = ∠CBD (Angles in the same segment of the circle)

Last Answer : Collective Bargaining Agent of CBA.

Description : If cba cde what is the distance between e and c?

Last Answer : Feel Free to Answer

Description : What is the full form of 'BCA' ? -How To ?

Last Answer : The full form of 'BCA' is Bachelor of Computer Application

Description : What is the best university or college for a BCA in Himachal Pradesh?

Last Answer : The needs of the market is changing, where more professionally-oriented freshers are on-demand than those with simple academical backgrounds. It is the duty of universities and colleges to ... famously known for having interesting courses such as they have recently introduced specialisation in two

Description : What does the following command do? grep −vn abc x (A) It will print all of the lines in the file x that match the search string abc (B) It will print all of the lines in file x that do not ... (D) It will print the specific line numbers of the file x in which there is a match for string abc

Last Answer : (A) It will print all of the lines in the file x that match the search string “abc”

Description : How to display all permutations of Strings in Java?

Last Answer : Well, how would you go about finding these permutations yourself, if you didn’t have the help of a computer program? Let’s think about this with the example of an easy, short word: test. You might start by fixing the beginning of the word in place, and only swapping the remaining letters… t

Description : Why doesn't this work (combinations and permutations)?

Last Answer : answer:It seems to me that in the multiplication you're attempting that you're double-counting some of the groups, aren't you? I'm having a hard time visualizing this, but I went to Wolfram ... first two women's choices are counted) The sum of these permutations is the same 285 that you expected.

Description : How to determine the difference between a problem that involves permutations and one that involves combinations?

Last Answer : answer:That example is indeed tough. At first glance you're not certain if the chronology of the meetings matters, or you're just determining which ten students get to have meetings. But ... each student does. Combinations generally focus on choosing a group, permutations focus on choosing a lineup.

Description : The letters of the word ‘COCHIN’ are permuted and all the permutations are arranged in alphabetical order as in English dictionary. -Maths 9th

Last Answer : answer:

Description : The tone of the poet is sarcastic. When he writes ‘All spaces are gridded filled with permutations of

Last Answer : The tone of the poet is sarcastic. When he writes All spaces are gridded filled with ... some more sarcastic lines having the same effect.

Description : How many four letter permutations can be formed from the first five letters of the alphabet?

Last Answer : Need answer

Description : How many distrinct permutations can be formed using the letters of the word Tennessee?

Last Answer : nkhnlk453

Description : How many district permutations can be formed using the letters of the word TENNESSEE?

Last Answer : Need answer

Description : How many distinct permutations can be formed using the letters of the word TENNESSEE?

Last Answer : Need answer

Description : DES works by using a. permutation and substitution on 64 bit blocks of plain text b. only permutations on blocks of 128 bits c. exclusive ORing key bits with 64 bit blocks d. 4 rounds of substitution on 64 bit blocks with 56 bit keys

Last Answer : a. permutation and substitution on 64 bit blocks of plain text 

Description : How many different possible permutations can be made from the word ‘WAGGISH’ such that the vowels are never together? A) 3605 B) 3120 C) 1800 D) 1240 E) 2140

Last Answer : Answer: C)  The word ‘WAGGISH’ contains 7 letters of which 1 letter occurs twice  = 7! / 2! = 2520 No. of permutations possible with vowels always together = 6! * 2! / 2!  = 1440 / 2 = 720 No. of permutations possible with vowels never together = 2520-720  = 1800.

Description : On a common hypotenuse AB, two right angled triangles, ACB and ADB are situated on opposite sides. -Maths 9th

Last Answer : According to question ∠BAC = ∠BDC.

Description : On a common hypotenuse AB, two right angled triangles, ACB and ADB are situated on opposite sides. -Maths 9th

Last Answer : According to question ∠BAC = ∠BDC.

Description : In the figure (not to scale ), O is the centre of the circle and `/_OBA=30^(@)`. Find `/_ ACB`

Last Answer : In the figure (not to scale ), O is the centre of the circle and `/_OBA=30^(@)`. Find `/_ ACB`

Description : In the above figure, O is the centre of the circle AB,AD and CD are the chords . If `/_ ADC=130^(@)` then fid `/_ ACB`.

Last Answer : In the above figure, O is the centre of the circle AB,AD and CD are the chords . If `/_ ADC=130^(@)` then fid `/_ ACB`.

Description : In the following figure, if `/_ AOB =60^(@)` then `/_ ACB=30^(@)`. [True `//` False `//` Cannot say ]

Last Answer : In the following figure, if `/_ AOB =60^(@)` then `/_ ACB=30^(@)`. [True `//` False `//` Cannot say ]

Description : In a uniform ring of resistance `R` there are two points `A` and `B` such that `/_ ACB = theta`, where `C` is the centre of the ring. The equivalent r

Last Answer : In a uniform ring of resistance `R` there are two points `A` and `B` such that `/_ ACB = theta`, where `C` ... ))` D. `(R )/(4pi^(2))(2pi-theta)theta`

Description : Why use the VCB at High Transmission System? Why can't use ACB?

Last Answer : Actually the thing is vacuum has high arc quenching property compare to air because in VCB, the die electric strengths equal to 8 times of air. That y always vacuum used as in HT breaker and air used as in LT.

Description : What do ABCB and ACB mean? 

Last Answer : ABCB – Air blast circuit breaker. ACB – Air circuit breaker. 

Description : What is the meaning of ACB, MCCB, NFB?

Last Answer : Air circuit breaker for 400V higher current ratings. Moulded case circuit breaker for 400V medium current ratings. No Fuse Breaker – 75 A capacity

Description : If you press the ACB Close button on an idle generator what will happen?

Last Answer : Ask E/O. Normally, the breaker won’t close until you synchronise, so even if you press the breaker close, it will not close. The breaker has under-voltage protection which will not let you close it.

Description : What is the full form of ACB?

Last Answer : Air circuit breaker. It is normally used at 400V and higher current applications (generator breakers).

Description : Once you have donated blood, is it easier to get a high BAC?

Last Answer : I really don't think it can make your ba increase because your body will still be absorbing the same amount of alcohol as it usually does. The blood to alcohol ratio will be a little off but ... for dehydration though, being that alcohol is a dia\uretic and you just gave blood. Drink lots of water

Description : do carrots go bac

Last Answer : Need Answer

Description : you can become an unsafe driver at bac levels of -General Knowledge

Last Answer : You can become an unsafe driver at BAC levels of: 0.08.

Description : warm and fuzzy bac range -General Knowledge

Last Answer : Someone is more likely to start to report feeling in a 'good mood' or 'warm and fuzzy' at 0.02 - 0.04% BAC range.