Using dev c++ 4
Hello I'm working on a little program for subnetting. Everything works, I just don't understand a particular thing. What I want to do is have the user enter in 15 characters that will be stored in a character array. Now to do this I'm using conio.h both for the gotoxy function and the getche function. I want to stop the input after the 15th character is entered or return is pressed. I'm using gotoxy to place the cursor after the field label such as "IP address: " thats all. This isn't the real program just a test one, but it will illustrate my point.
Code:
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include "conio.h"
using namespace std;
int i=0;
char ch[3];
void gotoxy(int x, int y) {
COORD c;
c.X = x - 1;
c.Y = y - 1;
SetConsoleCursorPosition (GetStdHandle(STD_OUTPUT_HANDLE), c);
}
int main()
{
gotoxy(0,30);
do {
++i;
ch[i]=getche();
} while (i <= 2);
cout << endl;
cout << ch[0];
cout << ch[1];
cout << ch[2];
system("PAUSE");
return 0;
}
I spent a good few hours looking how to get input one character at a time without the need to terminate. Any how, getche() and gotoxy() are conio.h function. what I need to know is why do I need to include the function void gotoxy() and not the int getche()? the getche works on its own apparently????
Rob