为什么终端输出不会并排

时间:2016-10-19 14:45:48

标签: c arrays terminal printf

#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
                      };

/ *&#34; * * ** * ** *
      * * * * * * *
  * * * * * * **** * * * * * * **** **** * **** **** * ** * ***** * * * * * * * * * * *****
    * **** * * **** * * ***** * * **** * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 **** * * * * * ***** * **** * * * * ** * * * * * * * * **** **** * *
* * * * * * * * * * *
* * * * * * * * * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * *
  * < / strong> * * * * * ** * * * * * * * * * * ** * * * * **** * * * * * * * ***** * /

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;
}

为什么当我在终端中运行时,我的代码不会并排编写字母而是将其权限缩小

2 个答案:

答案 0 :(得分:2)

每个打印行后都缺少换行符。这是它应该是这样的:

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
}

答案 1 :(得分:1)

问题在于: 1.索引变量的位置。 2.打印一行后不使用'\ n'。

此迁移有用

chars =0; // 0=a, 1=b, 2=c, ..... 25=z

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

for(rows = 0; rows <= 4; rows++){

    printf("%c", alfabetlow[chars][col][rows]);
    }
    printf("\n");

}