Click to See Complete Forum and Search --> : Using putchar() for output, not printing out how I want


Psytherium
January 27th, 2005, 09:21 AM
What my program does is read from a file and then prints out what is stored in an array.


7


67 7
XXX
X X
X
X
X
X X
XXX

49 5
X
XX
X
X
X
X
XXX


0

CC


That's the file it reads. first number at the top is the height of each character, then the first number above each letter/number is the character code. Second number is width. The 0 is the trigger number to start reading the input below it, and that's what it prints out, so it should be something like this

XXX XXX
X X X X
X X
X X
X X
X X X X
XXX XXX


but it prints out this...


XXX
XXX
X X
X X
X
X
X
X
X
X
X X
X X
XXX
XXX


Here is my output code:


for(int i=0;i<MAX_HEIGHT;i++)
{
for(int k=0;k<MAX_STRING&&charString[k]!=0;k++)
{
for(int j=0;j<MAX_WIDTH;j++)
{
if(j==1)
putchar(32);
int currentChar=charImage[charString[k]-32][i][j];
putchar(currentChar);
}
}
putchar(32);
}

cilu
January 27th, 2005, 10:53 AM
Pseudo-code:

* read the input file and store the letters in matrixes
* max_height = maximum height of a letter
i = 0
while (i<max_height)
{
for each letter do
* print the i row
print new line;
i = i + 1
}