-
x,y coordinates?
I'm currently working on an old-style text-based game for a class project, and have been able to figure most things out from reading books or others posts to figure out how to get things to work, but this one has me stumped as I've not found anything of the sort in a book or online.
Code:
printf("\nPlease fill out the following form...\n");
printf("\n");
printf("--------------------------------------------------------------------------------");
printf("|First Name: |");
printf("|Surname : |");
printf("| |");
printf("|Race : |");
printf("|Age : |");
printf("|Height : |");
printf("|Weight : |");
printf("|Eye Color : |");
printf("| |");
printf("|Alignment : (Good, evil, neutral) |");
printf("| |");
printf("| |");
printf("|Preferred Weapon Profeciency : (Sword, Mace, Axe, Staff)|");
printf("| |");
printf("| |");
printf("| |");
printf("| |");
printf("|-------------------------------------------------------------------------------");
I'm trying to figure out how to actually have a user enter their first name just after the firstname field, surname after the surname field, and so on, with the cursor blinking on the screen just after that point. Scanf didn't work considering it broke to a new line and would only display the form up to the point of scanf, and I was wanting it to show the whole form, then ask for the input of each field as they entered the previous one.
Thanks for any help ya'll can give to little ol' me.
-
There's no standard way to do what you're trying to do. It depends on what compiler, what OS, etc. you're using.
-
Ah ok,
Well thanks for lettin me know, guess I'll have to look into another way of figurin' this one out
Thanks for the quick response, though!
-
I think it works with a function from conio.h (i think in gcc this header is not available) .. something like gotoxy(x,y) where x and y are the coordinates of the point where you want your cursor to move.
-
Hi,
For Unix/Linux Platform use curses Library [ curses.h ]
For MS-DOS use the following code and make sure that the following conditions,
1. Printable character within (24,80) length.
2. Remove all new line("\n") character in the printf statement.
3. Use Common column value for all input.
Code:
#include <stdio.h>
#include <conio.h>
void main()
{
char fname[20],sname[20];
int age;
clrscr();
printf("Please fill out the following form...\n");
printf("");
gotoxy(5,3); /* gotoxy(column,row); */
printf("------------------------------------------------------------");
gotoxy(5,4);
printf("|First Name: |");
gotoxy(5,5);
printf("|Surname : |");
gotoxy(5,6);
printf("| |");
gotoxy(5,7);
printf("|Race : |");
gotoxy(5,8);
printf("|Age : |");
gotoxy(5,9);
printf("|Height : |");
gotoxy(5,10);
printf("|Weight : |");
gotoxy(5,11);
printf("|Eye Color : |");
gotoxy(5,12);
printf("| |");
gotoxy(5,13);
printf("|Alignment : (Good, evil, neutral) |");
gotoxy(5,14);
printf("| |");
gotoxy(5,15);
printf("| |");
gotoxy(5,16);
printf("|Preferred Weapon Profeciency : (Sword, Mace, Axe, Staff)|");
gotoxy(5,17);
printf("| |");
gotoxy(5,18);
printf("| |");
gotoxy(5,19);
printf("| |");
gotoxy(5,20);
printf("| |");
gotoxy(5,21);
printf("|------------------------------------------------------------");
gotoxy(18,4);
gets(fname);
gotoxy(18,5);
gets(sname);
gotoxy(18,8);
scanf("%d",&age);
}
Note : I have verified using Turbo C++ 3.0 and the output is perfect.
-
1) You use void main, which is flat out wrong. It never has been correct, and never will be correct.
2) The compiler you've "verified" it on is an old beyond belief, and the functions you use to do it are Borland specific. So naturally it worked on their compiler.
3) Your program has a ton of unneeded gotoxy lines.
4) You use gets, which also should never be used. Had you an updated compiler, such as GCC, it would tell you not to use it.
I suggest you go read the FAQ on points 1 and 4.
Quzah.
-
s.saran: Not a good way to start off on the boards.
But if you want a pretty looking console program, using curses or ncurses is probably a good idea.