there is (or was) a compiler extension (like getch) command in windows: gotoxy(x,y) that lets you type anywhere. It is extremely useful if you don't want to do this the hard way.
are you just wanting it for the default console settings or variable to user's settings? That is harder. You will as noted above need to fetch the width etc from the OS to do a variable one.
TBH, if you just want to get 99% of the code working, you can start with
1 2 3
int getScreenWidth() {
return 80;
}
For most tutorial / student examples, that's all you need.
If you need real widths from real consoles on real machines, then you only have to change the inside of the function. Everything else you've done will be complete unaffected.