incrementing letters and symbols

Hello. I'm new to C++ and need some help. I need to make a program that basically would output this:
a
b
c
...
aaa
aab
aac
...
aaz
aa0
aa1
...
aa9
aa!
aa@

etc.

I've tried several differnet ways to the point where i've butchered my code into something horrible. heres a snippet:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
char TheWord[]="!!!!!!!!";
void increment()
{

unsigned char exitloop=1;


	for (int c=sizeof(TheWord); (c>=0)&&(exitloop!=0);c--) 
	{
		if (TheWord[c]<'~') 
        {
            TheWord[c]++;			
			exitloop=0;			
        }
		
	
		else
			TheWord[c]='!'; 
	} 

}
void Loop()
{
	for (int x=0;x<2000;x++)
	{
		incValue();		
		cout << TheWord << endl;
	}
}


Then I would run the Loop() function in the main() section.

I know I'm missing something obvious but i've got like writers block or something going on. Any suggestions appreciated Thanks!
Forget about words and focus on the characters.

Are you familiar with the ASCII coding of characters? Take a look at the ASCII table and it should be clear that letters are represented as numbers, and that there's a sequence to this representation that makes it very convenient to do the sort of output that you're ask about.
Yes I'm familiar with those which is basically what I was trying to do...Not a very good job though. the variable TheWord is not suggesting that im creating words. For some reason when I increment from certain letters the code just outputs something weird for no reason. I jokingly call it "the matrix" because of its random output on the console.
ASCII is a 7bit code, but with a byte, you have 8bits, so the last 127 are vendor specific.

You need to think about what needs to be displayed and get the range of numbers that falls into and only iterate thru that range.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#define LO 0x21
#define HI 0x7E

extern "C"

using namespace std;
double base = 125;

FILE* pFile;
double lift;
char TheWord[63];



void Fill(double lift){
	for(int c = 0; c < lift-1; c++){
			TheWord[c] = '!';
		}
}

void incValue(double lift)
{	
	unsigned char exitloop=1;

	
		for (int c=lift-1; (c>=0)&&(exitloop!=0);c--) 
		{
			if (TheWord[c]< HI) 
			{
				TheWord[c]++;			
				exitloop=0;			
			}
			
		
			else
				TheWord[c]=LO; //reset value to !
		} 
		

}

void LoopThroughValues(double digit)
{
	double xxx = pow(base,lift);
	pFile = fopen("dict.txt", "a");
	for (int x=0;x<=xxx;x++)
	{
		incValue(digit);		
		fputs(TheWord,pFile);
		fputs("\n",pFile);
		//cout << TheWord << endl;
	}
}


Thats my code except the output i get in the file looks like this:
!
!
!
!
!
!
!
!
!
!

!
!
!

!
!
!
!
!
!
!
!&
![
!]
!<
!>
!

!
!
!
!
!
!
!!
!"
!#

I'm not really sure where those crazy symbols come from....
I agree with kbw .. you will need three loop which will display the char , corresponding the ascii decimal . hope you will get the loop right ( 0 - 127)
Wow, that looks incredibly complicated. I can't see how that contributes to the solution.

Have you tried a prototype that just prints the lowercase letters? Maybe that'll help you get to a handle on what's required.
Last edited on
Topic archived. No new replies allowed.