x,y coordinates?

This is a discussion on x,y coordinates? within the C Programming forums, part of the General Programming Boards category; I'm currently working on an old-style text-based game for a class project, and have been able to figure most things ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    2

    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.

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,171
    There's no standard way to do what you're trying to do. It depends on what compiler, what OS, etc. you're using.
    If you understand what you're doing, you're not learning anything.

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    2
    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!

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    4
    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.

  5. #5
    Saravanan S-CH s.saran's Avatar
    Join Date
    Dec 2004
    Location
    India
    Posts
    4
    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.

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    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.
    Hope is the first step on the road to disappointment.

  7. #7
    ---
    Join Date
    May 2004
    Posts
    1,379
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to get relative mouse coordinates when GLUT return absolute
    By joeprogrammer in forum Game Programming
    Replies: 14
    Last Post: 02-10-2009, 06:35 PM
  2. values into array based on coordinates
    By BabyWasabi in forum C++ Programming
    Replies: 1
    Last Post: 12-13-2006, 07:48 PM
  3. Global coordinates in OpenGL?
    By IcyDeath in forum C++ Programming
    Replies: 1
    Last Post: 11-25-2004, 06:29 PM
  4. Converting from Screen to World Coordinates
    By DavidP in forum Game Programming
    Replies: 9
    Last Post: 05-11-2004, 01:51 PM
  5. Size of 1 pixel
    By ooosawaddee3 in forum C++ Programming
    Replies: 4
    Last Post: 07-26-2002, 09:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21