- 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
6 Answers
+ 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
+ 3
Use formatting like
printf("\t\t\t this text is in center");
+ 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 ......
+ 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
0
use loop ,'\t' and '\n' to make your code center of the string.
0
Any other solution..?