简体   繁体   中英

How to print compacted points in pure C, so they can be seen as a single mathematical figure (line, square, rectangle, etc.)?

In the following code I'm printing 10 points in a straight line. How can I make these points be compacted so that someone can see all of them as an almost continuous line without, using any graphical library?

#include <stdio.h>
int main()
{
    for (int i=0; i<10; i++)
        printf("%c", '.');
    return 0;
}
          ,
         _o_
    ._ ,'   `o'
----(_)      :       ^aNT
    '  `.   .o
         ~o~  `
          '

A "picture" is worth a thousand words.

How can I make these points be compacted so that someone can see all of them as an almost continuous line without, using any graphical library?

You can´t do that by using points. You need to print fe subsequent _ characters to print a line, fe:

printf("_______________");

If you want to use vertical lines, use the | character in subsequent calls to printf:

printf("|\n");
printf("|\n");
printf("|\n");
printf("|\n");

or just

printf("|\n|\n|\n|\n|\n");

One example:

#include <stdio.h>

int main(void)
{    
   printf("___________________________\n");
   printf("|    ````        ````     |\n");
   printf("|      X         X        |\n");
   printf("|           O             |\n");
   printf("|                         |\n");
   printf("|   |________________|    |\n");
   printf("|         |____|          |\n");
   printf("|_________________________|\n");
}

Output:

___________________________       
|    ````       ````      |              
|      X         X        |            
|           O             |      
|                         |                               
|   |________________|    |           
|         |____|          |  
|_________________________|

It is not the most beautiful look but that should achieve what you want as far as I understood your question. You don´t need special libraries to accomplish simple graphical illustrations in the console.

How to print compacted points in pure C, so they can be seen as a single mathematical figure (line, square, rectangle, etc.)?

A console is not meant to output shapes and figures like that. Maybe there are some terminals with special fonts, but it is hard if not impossible to achieve.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM