I want my text to be horizontally centered in the terminal. How can I do this in C?
To expand on @eyalm's answer: if you got COLUMNS var, you can center the lines like this:
COLUMNS
int columns = strtol(getenv("COLUMNS"), NULL, 10); int fwidth = strlen(s) + (columns - strlen(s)) / 2; printf("%*s\n", fwidth, s);
If you are working with bash use an environment variable COLUMNS to get the width and calculate the center.
If you are lazy, how can I write all this code, this is a simple solution.
Console.WriteLine(" Hello World"); Console.ReadLine();
Add more space if needed to the center lol