Skip to content

Instantly share code, notes, and snippets.

@pwnwriter
Created October 31, 2022 07:19
Show Gist options
  • Save pwnwriter/7ceb3a8cf47946c4647b6781b1ccde75 to your computer and use it in GitHub Desktop.
Save pwnwriter/7ceb3a8cf47946c4647b6781b1ccde75 to your computer and use it in GitHub Desktop.
// print text in center !
#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
int main(void)
{
char name[] = "pwnwriter";
struct winsize pwnwriter; //using a structure defined in unistd.h library.....
ioctl(STDIN_FILENO, TIOCGWINSZ, &pwnwriter); /*calling te ioctl function... it save the window detail
pwnwriter structure*/
int widthToPrintName = pwnwriter.ws_col / 2; /*dirvinding the total width by 2 to write
text in center*/
for (int i = 1; i <= widthToPrintName; ++i)
printf(" "); //printing the half screen with space..
printf("%s\12", name); //printing the name
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment