dominic baker dominic baker - 1 month ago 7
C Question

why wont the output in terminal line up side by side

#include <string.h>
#include <stdio.h>

int rows;
int col;
int chars;
int callLetter;
int characters;
int counter;


char userinput[100];

char alfabetlow[26][7][5] = {{" "," "," *** "," *"," ****","* *"," *** "},//lower case a

{"* ","* ","* ","**** ","* *","* *"," *** "},//lower case b

{" "," "," *** ","* *","* ","* *"," *** "},//lower case c

{" *"," *"," *"," ****","* *","* *"," *** "},//lower case d

{" "," "," *** ","* *","*****","* "," *** "},//lower case e

{"* ","* ","* ","**** ","* *","* *"," *** "},//lower case f

{"* ","* ","* ","**** ","* *","* *"," *** "},//lower case g

{"* ","* ","* ","**** ","* *","* *"," *** "},//lower case h

{"* ","* ","* ","**** ","* *","* *"," *** "},//lower case i

{"* ","* ","* ","**** ","* *","* *"," *** "},//lower case j

{"* ","* ","* ","**** ","* *","* *"," *** "},//lower case k

{"* ","* ","* ","**** ","* *","* *"," *** "},//lower case l

{"* ","* ","**** ","* * *","* * *","* * *","* * *"},//lower case m

{" "," ","**** ","* *","* *","* *","* *"},//lower case n

{" "," "," *** ","* *","* *","* *"," *** "},//lower case o

{" "," ","**** ","* *","**** ","* ","* "},//lower case q

{" "," "," ****","* *"," ****"," *"," *"},//lower case q

{" "," ","* ** ","* *","* ","* ","* "},//lower case r

{" "," "," *** ","* "," *** "," *"," *** "},//lower case s

{" * "," * ","*****"," * "," * "," * *"," ** "},//lower case t

{" "," ","* *","* *","* *","* *"," ****"},//lower case u

{" "," ","* *","* *"," * * "," * * "," * "},//lower case v

{" "," ","* *","* *","* * *","* * *"," * * "},//lower case w

{" "," ","* *"," * * "," * "," * * ","* *"},//lower case x

{" "," ","* *"," * * "," * "," * ","* "},//lower case y

{" "," ","*****"," * "," * "," * ","*****"},//lower case z
};


/*" * * ** * ** *

* * * * * * *

* * * * * * **** * * * * * * **** **** * **** **** * ** * ***** * * * * * * * * * * *****

* **** * * **** * * ***** * * **** * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

**** * * * * * ***** * **** * * * * ** * * * * * * * * **** **** * *
* * * * * * * * * * *

* * * * * * * * * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * *

* * * * * * ** * * * * * * * * * * ** * * ** **** * * * * * * * *****
*/

int main(int argc, char const *argv[])
{

while(characters != EOF && characters != '\n'){
characters = getchar();
userinput[counter] = characters;
counter++;
}


for(col = 0; col <= 25; col++){


for(rows = 0; rows <= 6; rows++){
printf("%c", alfabetlow[rows][col][chars]);
}
}


/*//prints down over
for(col = 0; col <= 6; col++){
for(row = 0; row <= 25; row++){
for(chars = 0; chars <= 4; chars++){
printf("%c", alfabetlow[row][col][chars] );
}
printf("");
}
printf(" ");

}*/

return 0;
}


why when i run in terminal will my code not write the alphabet side by side instead it rights down over

Answer

You're missing newline after every printed row. Here's how it should look like:

for(int col = 0; col <= 6; col++)
{
  for(int row = 0; row <= 25; row++)
  {
    for(int chars = 0; chars <= 4; chars++)
    {
      printf("%c", alfabetlow[row][col][chars] );
    }
    printf(" "); // You may also add a space between characters.
  }
  printf("\n"); // New line after each row
}
Comments