Write a program to write a given string in maximum
possibilities?
i.e str[5]="reddy";
i.e we can write this string in 120 ways
for that write a program

Answer Posted / sunil singh

Hello dear....
sorry for my misunderstanding for the question..
please check this code it might help you..
************************************************************
#include "stdafx.h"
#include "string.h"
#include "conio.h"

#define BUFFER_SIZE 256

int fcto(int value)
{
int result;

if(value <= 1)
{
return 1;
}
else
{
return (value*fcto(value-1));
}
}
void PrintAllValues(char *ptr,int number)
{
char backup[BUFFER_SIZE],*first, *second,*temp1;
int loop, length;
char result[BUFFER_SIZE];
char temp,temp12;
int count =0,i;
static int serial =0;
memset(backup,0x00, BUFFER_SIZE);
memset(result,0x00, BUFFER_SIZE);
memcpy(result,ptr,BUFFER_SIZE);
memcpy(backup,ptr,BUFFER_SIZE);
first = second = result;
temp1 = backup;
length= strlen(result);
printf("\r\n%s - %d",result,serial);
for(loop=1;loop<=number;)
{
second += count;
first += count;
if(*(first+1) == '\0')
{
temp = result[0];
for(i = 0 ; i < length;i++)
{
if(i == 0)
{
temp =result[i];
result[i] = result[length-1];
}
else
{
temp12 = result[i];
result[i] = temp;
temp = temp12;
}
}
memcpy(backup,result,BUFFER_SIZE);
first = second = result;
count = 0;
loop++;
serial++;
printf("\r\n%s - %d",result,serial);
}
while((*second != '\0') && (loop <= number))
{
serial++;
loop++;
if(*first != *second)
{
temp = *first;
*first = *second;
*second = temp;
second++;
first++;
printf("\r\n%s - %d",result,serial);
}
else
{
printf("\r\n****** - %d",serial);
second++;
}

}
memcpy(result,backup,BUFFER_SIZE);
first = second = result;
count++;
}
}

int main()
{
char *ptr = "abcdef";// enter the string
int data1;

data1 = fcto(strlen(ptr));
PrintAllValues(ptr,data1);

getch();
return 0;
}
************************************************************

Please let me know if you face any problem.

Thanks
sunil

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Explain what are run-time errors?

601


If fflush wont work, what can I use to flush input?

599


Was 2000 a leap year?

616


What is the use of void pointer and null pointer in c language?

616


general for is %wd,f-d; in this system "w" means a) 'w' represent total width of digits b) 'w' represent width which includes the digits before,after decimal place and the decimal point c) 'w' represent width which includes the digits before only d) 'w' represent width after decimal place only

576






What is the purpose of the following code? Is there any problem with the code? void send(int count, short *to, short *from) { /* count > 0 assumed */ register n = (count + 7) / 8; switch (count % 8) { case 0: do { *to = *from++; case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while (--n > 0); } }

1948


What is the use of sizeof () in c?

547


What is the purpose of sprintf() function?

589


What do you understand by friend-functions? How are they used?

633


a linearly ordered set of data elements that have the same structure and whose order is preserved in storage by using sequential allocation a) circular b) ordinary c) array d) linear list

626


How a string is stored in c?

574


Can a variable be both constant and volatile?

551


Which is an example of a structural homology?

768


.find the output of the following program? char*myfunc(char*ptr) { ptr +=3; return (ptr); } int main() { char*x,*y; x="HELLO"; y=myfunc(x); printf("y = %s ",y); return 0; }

1982


What is the advantage of using #define to declare a constant?

611