- 1

How to print name or string in the center in c language?

I want to print my name at the center of the screen

14th May 2021, 12:57 PM
ATUL AAGE
ATUL AAGE - avatar
6 odpowiedzi
+ 1
#include <stdio.h> #include <string.h> void disp(char *a, int b) { for (int i=(b-strlen(a))/2;i;i--) { putchar(32); } puts(a); } /* Where 'a' is the char pointer containing the text to be displayed and 'b' is the screen width (max no of characters a single line can accommodate). */ // Hope this helps
14th May 2021, 7:50 PM
Calvin Thomas
Calvin Thomas - avatar
+ 3
Use formatting like printf("\t\t\t this text is in center");
14th May 2021, 1:08 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Yes in graphics you can use outtextxy() function this will format your output correctly but its little tough to use becz u have to know proper dimensions of coordinate. outtextxy(130,130,"your text"); In c++ you can use manipulators like setw ......
14th May 2021, 5:32 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
you first need to query for the screen width (how many characters stand on one line), then substract to it the length of your text, and divide by 2 to get how many spaces you must put before yout text to center it ;P
14th May 2021, 5:34 PM
visph
visph - avatar
0
use loop ,'\t' and '\n' to make your code center of the string.
14th May 2021, 1:13 PM
Adnan Chowdhury
Adnan Chowdhury - avatar
0
Any other solution..?
14th May 2021, 5:24 PM
ATUL AAGE
ATUL AAGE - avatar