I am Completely new to programming. I am trying to make a very basic Ncurses game. My problem is that I have some very repetitive code where I take a string, calculate the length of it, divide it by 2, then subtract from the amount of columns. I do this so I can center my text on the screen. I want to make this easier by making a function, but I don't know how to make a function that returns the Ncurses function mvprintw(y,x,string)
Here is my code so you can understand better:
#include <iostream>
#include <ncurses.h>
#include <string.h>
int main(){
initscr();
int x,y;
getmaxyx(stdscr, y, x);
mvprintw(0,x/2-(strlen("************")/2), "************");
mvprintw(1,x/2-(strlen("Welcome")/2), "Welcome");
mvprintw(2,x/2-(strlen("************")/2), "************");
refresh();
getch();
endwin();
return 0;
}