Partage
  • Partager sur Facebook
  • Partager sur Twitter

Déplacer le curseur en console

LOCATE

    5 juin 2006 à 19:31:10

    Quand on est en console, j'aimerais trouver en moyen d'aller directement ligne 1, colonne 1, ou ligne 20, colonne 10, sans bien calculer son coup avec des \n et des \t.
    • Partager sur Facebook
    • Partager sur Twitter
      5 juin 2006 à 19:38:41

      Je crois qu'il faut utiliser la librairie Conio.h avec sa fonction gotoxy.
      • Partager sur Facebook
      • Partager sur Twitter
        5 juin 2006 à 19:41:54

        [Linker error] undefined reference to `gotoxy'
        • Partager sur Facebook
        • Partager sur Twitter
          17 juin 2006 à 10:41:52

          Si quelqu'un savait comment faire...
          • Partager sur Facebook
          • Partager sur Twitter
          Anonyme
            17 juin 2006 à 11:46:52

            Alors, la fonction gotoxy est dans le fichier conio.h, mais dans une version que quasi aucun compilateur n'a.
            Je vais aller vite chercher ce fichier sur mon ancien pc, il te suffira de copier son contenu et de le coller dans un nouveau fichier que tu sauve à la place du conio.h que tu à.
            Il faut aussi linker conio.c que tu n'a pas (je pense)


            [EDIT] Voilà voilà, tu les mets dans le dossier Includes de ton IDE et tu linke conio.c à ton projet

            conio.c
            /* A conio implementation for Mingw/Dev-C++.
             *
             * Written by:
             * Hongli Lai <hongli@telekabel.nl>
             * tkorrovi <tkorrovi@altavista.net> on 2002/02/26.
             * Andrew Westcott <ajwestco@users.sourceforge.net>
             *
             * Offered for use in the public domain without any warranty.
             */


            #ifndef _CONIO_C_
            #define _CONIO_C_

            #include <stdio.h>
            #include <stdlib.h>
            #include <unistd.h>
            #include <windows.h>
            #include <string.h>
            #include "conio.h"

            #ifdef __cplusplus
            extern "C" {
            #endif

            static int __BACKGROUND = BLACK;
            static int __FOREGROUND = LIGHTGRAY;


            void
            clrscr ()
            {
                DWORD written;

                FillConsoleOutputAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
                  __FOREGROUND + (__BACKGROUND << 4), 2000, (COORD) {0, 0},
                  &written);
                  FillConsoleOutputCharacter (GetStdHandle
                  (STD_OUTPUT_HANDLE), ' ',
                  2000, (COORD) {0, 0}, &written);
                gotoxy (1, 1);
            }


            void
            clreol ()
            {
                COORD coord;
                DWORD written;
                CONSOLE_SCREEN_BUFFER_INFO info;

                GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE),
                  &info);
                coord.X = info.dwCursorPosition.X;
                coord.Y = info.dwCursorPosition.Y;

                FillConsoleOutputCharacter (GetStdHandle (STD_OUTPUT_HANDLE),
                  ' ', info.dwSize.X - info.dwCursorPosition.X, coord, &written);
                gotoxy (coord.X, coord.Y);
            }


            void
            delline()
            {
                COORD coord;
                DWORD written;
                CONSOLE_SCREEN_BUFFER_INFO info;

                GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE),
                  &info);
                coord.X = info.dwCursorPosition.X;
                coord.Y = info.dwCursorPosition.Y;

                FillConsoleOutputCharacter (GetStdHandle (STD_OUTPUT_HANDLE),
                  ' ', info.dwSize.X * info.dwCursorPosition.Y, coord, &written);
                gotoxy (info.dwCursorPosition.X + 1,
                info.dwCursorPosition.Y + 1);
            }


            int
            _conio_gettext (int left, int top, int right, int bottom,
              char *str)
            {
                int i, j, n;
                SMALL_RECT r;
                CHAR_INFO buffer[25][80];

                r = (SMALL_RECT) {left - 1, top - 1, right - 1, bottom - 1};
                ReadConsoleOutput (GetStdHandle (STD_OUTPUT_HANDLE),
                  (PCHAR_INFO) buffer, (COORD) {80, 25}, (COORD) {0, 0}, &r);

                lstrcpy (str, "");
                for (i = n = 0; i <= bottom - top; i++)
                for (j = 0; j <= right - left; j++)
                {
                    str[n] = buffer[i][j].Char.AsciiChar;
                    n++;
                }
                str[n] = 0;
                return 1;
            }


            void
            gotoxy(int x, int y)
            {
              COORD c;

              c.X = x - 1;
              c.Y = y - 1;
              SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
            }


            void
            puttext (int left, int top, int right, int bottom, char *str)
            {
                int i, j, n;
                SMALL_RECT r;
                CHAR_INFO buffer[25][80];

                memset (buffer, 0, sizeof (buffer));
                r = (SMALL_RECT) {left - 1, top - 1, right - 1, bottom - 1};

                for (i = n = 0; i <= bottom - top; i++)
                for (j = 0; j <= right - left && str[n] != 0; j++)
                {
                    buffer[i][j].Char.AsciiChar = str[n];
                    buffer[i][j].Attributes = FOREGROUND_BLUE | FOREGROUND_GREEN | FOREGROUND_RED;
                    n++;
                }

                WriteConsoleOutput (GetStdHandle (STD_OUTPUT_HANDLE),
                  (CHAR_INFO *) buffer, (COORD) {80, 25},
                  (COORD) {0, 0}, &r);
            }


            void
            _setcursortype (int type)
            {
                CONSOLE_CURSOR_INFO Info;

                Info.dwSize = type;
                SetConsoleCursorInfo (GetStdHandle (STD_OUTPUT_HANDLE),
                  &Info);
            }


            void
            textattr (int _attr)
            {
                SetConsoleTextAttribute (GetStdHandle(STD_OUTPUT_HANDLE), _attr);
            }


            void
            textbackground (int color)
            {
                __BACKGROUND = color;
                SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
                  __FOREGROUND + (color << 4));
            }


            void
            textcolor (int color)
            {
                __FOREGROUND = color;
                SetConsoleTextAttribute (GetStdHandle (STD_OUTPUT_HANDLE),
                  color + (__BACKGROUND << 4));
            }


            int
            wherex ()
            {
                CONSOLE_SCREEN_BUFFER_INFO info;

                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
                return info.dwCursorPosition.X + 1;
            }


            int
            wherey ()
            {
                CONSOLE_SCREEN_BUFFER_INFO info;

                GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &info);
                return info.dwCursorPosition.Y + 1;
            }


            #ifdef __cplusplus
            }
            #endif

            #endif /* _CONIO_C_ */


            conio.h
            /* A conio implementation for Mingw/Dev-C++.
             *
             * Written by:
             * Hongli Lai <hongli@telekabel.nl>
             * tkorrovi <tkorrovi@altavista.net> on 2002/02/26.
             * Andrew Westcott <ajwestco@users.sourceforge.net>
             *
             * Offered for use in the public domain without any warranty.
             */


            #ifndef _CONIO_H_
            #define _CONIO_H_


            #include <stdio.h>

            #ifdef __cplusplus
            extern "C" {
            #endif

            #define BLINK 0

            typedef enum
            {
                BLACK,
                BLUE,
                GREEN,
                CYAN,
                RED,
                MAGENTA,
                BROWN,
                LIGHTGRAY,
                DARKGRAY,
                LIGHTBLUE,
                LIGHTGREEN,
                LIGHTCYAN,
                LIGHTRED,
                LIGHTMAGENTA,
                YELLOW,
                WHITE
            } COLORS;


            #define cgets   _cgets
            #define cprintf _cprintf
            #define cputs   _cputs
            #define cscanf  _cscanf
            #define ScreenClear clrscr

            /* blinkvideo */

            void clreol (void);
            void clrscr (void);

            int _conio_gettext (int left, int top, int right, int bottom,
                                char *str);
            /* _conio_kbhit */

            void delline (void);

            /* gettextinfo */
            void gotoxy(int x, int y);
            /*
            highvideo
            insline
            intensevideo
            lowvideo
            movetext
            normvideo
            */


            void puttext (int left, int top, int right, int bottom, char *str);

            // Screen Variables

            /* ScreenCols
            ScreenGetChar
            ScreenGetCursor
            ScreenMode
            ScreenPutChar
            ScreenPutString
            ScreenRetrieve
            ScreenRows
            ScreenSetCursor
            ScreenUpdate
            ScreenUpdateLine
            ScreenVisualBell
            _set_screen_lines */


            void _setcursortype (int type);

            void textattr (int _attr);

            void textbackground (int color);

            void textcolor (int color);

            /* textmode */

            int wherex (void);

            int wherey (void);

            /* window */



            /*  The code below was part of Mingw's conio.h  */
            /*
             * conio.h
             *
             * Low level console I/O functions. Pretty please try to use the ANSI
             * standard ones if you are writing new code.
             *
             * This file is part of the Mingw32 package.
             *
             * Contributors:
             *  Created by Colin Peters <colin@bird.fu.is.saga-u.ac.jp>
             *
             *  THIS SOFTWARE IS NOT COPYRIGHTED
             *
             *  This source code is offered for use in the public domain. You may
             *  use, modify or distribute it freely.
             *
             *  This code is distributed in the hope that it will be useful but
             *  WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
             *  DISCLAMED. This includes but is not limited to warranties of
             *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
             *
             * $Revision: 1.4 $
             * $Author: hongli $
             * $Date: 2002/04/26 19:31:25 $
             *
             */


            char*   _cgets (char*);
            int     _cprintf (const char*, ...);
            int     _cputs (const char*);
            int     _cscanf (char*, ...);

            int     _getch (void);
            int     _getche (void);
            int     _kbhit (void);
            int     _putch (int);
            int     _ungetch (int);


            int     getch (void);
            int     getche (void);
            int     kbhit (void);
            int     putch (int);
            int     ungetch (int);


            #ifdef __cplusplus
            }
            #endif

            #endif /* _CONIO_H_ */


            • Partager sur Facebook
            • Partager sur Twitter

            Déplacer le curseur en console

            × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
            × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
            • Editeur
            • Markdown