C program to replace all the letters of a string with all 26 alphabets and to do permutations to all the substituted ones and finally store the resulted strings in a file..

please help me out in fixing this situation..
To be clear. let me quote an example:

If i havva simple 2 letter word eg: "TO". Then those two letters in the String "TO" are to be replaced by 26 English alphabets character by character individually..
like>>>
Given string: TO
OUTPUT should be like:
AO
BO
CO
DO
EO
.
.
.
ZO
and
TA
TB
TC
TD
TE
.
.
.
.
TZ
and the above generated string permutations(with repetition {n^r} ). such that we should get 26*26 ie.,676 permutations.
I hope u understood the logic..
And these whole set of 676 strings are to be stored in a file.
thanq...

What have you coded so far?

Thanx fr ur reply.
Here im able to replace with alphabets a letter by letter. and have a code for permutations even. But couldn't make it loop for replacing the character with all 26 alphabets..
CODE:
#include<stdio.h>
#include<string.h>
#include<conio.h>
main()
{
char *string = "dogood";
char zev[50];
int length = strlen(string);
printf("\n %d \n",strlen(string));
int i;
for(i=0;i<l;i++)
{
if(*string=='o')
string='n';
else
zey = *string;
*string++;
}
for(i=0;i<l;i++)
printf("%c",zey);
printf("\n");
getch();
}

I suggest you use a reference string for the alphabets
then you need to use a nested loop
one to replace an index with every character from the reference string
and the other loop for every character of the word

Thanks for the information. its working well.

I think if we are clear.
My program should be like:
-------> If we give some string of length 'n' (eg: GAVC here its length is 4)

-------> This program should read this string GAVC from an input file and generate the permutations of those substituted in to the other file.

-------> Then every position in the string are to be <b>substituted by 20 letters</b> (A, C, D, E, F, G, H, I, K, L, M, N, P, Q, R, S, T, V, W, Y ) and <b>not with 26 alphabets</b> and then permutations should be done on those individual characters in the given string.

-------> Such that if we give the above string GAVC of length 4, the program should generate 20^4 permutations ie., 160000 combinations.


Please find a solution for me on this........
Thanq..
Reply

The code i have so far is:

#include<stdio.h>
#include<conio.h>
#include<string.h>
main()
{
      int i;
    FILE *fr,*fw;
    fr = fopen("input.txt","r");
    fw = fopen("output.txt","w");
    char *string="gavc",zev[50];
int length = strlen(string);
printf("\n %d \n",strlen(string));
    char ch;
fprintf(fw,"The string is:---> ");
    while(1)
    {
    ch = getc(fr);
    if(ch==EOF)
    {
    break;
    }
    else
    putc(ch,fw);
    }


                       int *ipCount = new int[strlen(zev)];
                       for(int i= 0;i<strlen(zev);i++)
                       {
                               ipCount[i]=25;
                       }
                       while(ipCount[0]>=0)
                       {

                               for(int j=0;j<26;j++)
                               {
                                       printf("%s\n",zev);
                                       zev[strlen(zev)-1]++;
                                       ipCount[strlen(zev)-1]--;

                               }
                               for(int i= 1;i<strlen(zev);i++)
                               {

                                       if(ipCount[0]==0)
                                      {
                                           ipCount[0]=-1;
                                      }
                                       if(ipCount[i]==0 )
                                       {
                                               ipCount[i-1]=ipCount[i-1]-1;
                                               zev[i-1]++;
                                               for(int k=i;k<strlen(zev);k++)
                                               ipCount[k]=25;
                                               break;
                                       }

                               }

                       }

fprintf("fw","\n %s \n",zev);
    fprintf(fw,"\n combinations generated  are:\n");
    printf("\n %s \n",zev);
    fclose(fr);
    fclose(fw); 
    getch();
}

4 posts -- all very poor. Maybe this will help you get better help, by giving better information:

[boilerplate_help_info]

Posting requests for help must be well thought out if you want help quickly and correctly.  Your post did not meet the criteria for quality help. You may get some posts, but are they going to be useful?  Check your post with these checkpoints - what is it [i]you[/i] missed:
[list=1]
[*]Ask a question that can be answered. Do not ask
- What's wrong with my code?
- Why doesn't this work?
- Anything else that does not give us useful information.
[*]Post your code.  If we don't know what you did, how can we possibly help?
- Use [b]PROPER FORMATTING[/b] -- see this
- Use CODE Tags so your formatting is preserved.
If we can't follow your code, it's difficult to help. We don't care that you're still working on it. If you want us to read it, it must be readable
[*]Explain what the code is supposed to do.  If we don't know where the target is, how can we help you hit it?
[*]Explain what actually happened! If we don't know where the arrow went when you shot it, how can we tell what went wrong and how far from the target you are?
[*]If you have errors, post them! We can't see your screen.  We can't read your mind. You need to tell us what happened.
[*]Do [b]not[/b] ask for code. We are not a coding service. We will help you fix your code. 
    If anyone posts working code for you, they are a cheater. 
    If you use that code [i]you[/i] are a cheater.
[*]Do [b]not[/b] bore us with how new you are. We can tell by your code.
- Do not apologize. We were all new, and unless you are completely 
  brain dead you will get better.
- Do not ask us to "take it easy on you."
- Do not say "I don't know what's going on." That's obvious since
  you posted for help. Use that time wisely by [b]explaining[/b] as best 
  you can so we can help.
[*]Do not apologize for posting 'late'. We don't have any expectations on when you should be posting - 10 minutes or 10 days. We aren't timing your responses.
[*][b]Do not post your requirements and nothing else. [/b]We view that as a lazy do-nothing student that wants us to do their work for them. That's cheating and we [i]will[/i] be hard on you.
[*]Do not attach files except when absolutely necessary. Most of us are not going to download files.  Add the information to your post.
[*][b]Do not tell us how urgent it is.[/b] Seriously, for us there is no urgency at all. Many that can help will ignore any URGENT or ASAP requests.
[*]Create a [b][i]good[/i][/b] title for your post. The title [b]C++[/b] in the C++ forum is bloody redundant and worthless!  [b]What's wrong?[/b] equally so. Specifically what are you having trouble with? [i]There[/i] is your title. [i](note: [b]my program[/b] is not the answer.)[/i]
[/list]
Think more about your next post so we don't have to play 20 questions to get the info we need to help you.

[/boilerplate_help_info]

yeah thanx alot...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.