Thread: String counter increase thingy problem : )

  1. #1
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330

    String counter increase thingy problem : )

    I'm trying to make a program that'll take a string (say, "aaaaaaaa") and convert it to "zzzzzzzz" through incrementation. For example
    aaaaaaaa
    aaaaaaab
    aaaaaaac
    ...
    aaaaaaaz
    aaaaaaba
    aaaaaabb
    aaaaaabc

    until,
    zzzzzzzzz

    This is what I have done so far (i'm a n00bie :P )

    do {
    vl[1] = FN[1];
    vl[2] = FN[2];
    vl[3] = FN[3];
    vl[4] = FN[4];
    vl[5] = FN[5];
    vl[6] = FN[6];
    vl[7] = FN[7];
    vl[8] = FN[8];
    vl[1]++;

    if (vl[1] > 122) { vl[2]++; CH++;}
    if (vl[2] > 122) { vl[3]++; CH++;}
    if (vl[3] > 122) { vl[4]++; CH++;}
    if (vl[4] > 122) { vl[5]++; CH++;}
    if (vl[5] > 122) { vl[6]++; CH++;}
    if (vl[6] > 122) { vl[7]++; CH++;}
    if (vl[7] > 122) { vl[8]++; CH++;}
    if (vl[8] > 122) { goto en; }
    for (t = 0; t != 8; t++) { cout << vl[t] << endl; }
    } while (xx == 0);
    en:
    cout << endl << CH << endl;
    return(0);
    }

  2. #2
    of Zen Hall zen's Avatar
    Join Date
    Aug 2001
    Posts
    1,007
    You could use a couple of for loops -

    Code:
    #include <iostream>
    #include <cstring>
    
    using namespace std;
    
    int main()
    {
    	char a []="aaaaaaaa";
    
    	for(int j=strlen(a)-1;j>=0;j--)
    		for(int i='a';i<='z';i++)
    		{
    			a[j]=i;
    			cout << a << endl;
    		}
    	
    
    	return 0;
    }
    zen

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. string problem
    By INeedSleep in forum C++ Programming
    Replies: 24
    Last Post: 11-08-2007, 11:52 PM
  2. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  3. Another overloading "<<" problem
    By alphaoide in forum C++ Programming
    Replies: 18
    Last Post: 09-30-2003, 10:32 AM
  4. String deletion problem
    By NightWalker in forum C Programming
    Replies: 1
    Last Post: 09-17-2003, 10:23 AM
  5. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM