This isn't the full program but I rewrote the functional part that is causing the problem. The program i'm working on is going to be used to calculate subnets and vlsm's. All I'm asking of c++ and getche() is that It will prevent the user from starting the ip address (or octet of ip address) with a dot, just as a form a validation. anyway they problem is with a seemingly unrelated piece of code, specifically dot_count++, whenever this line is in my code for some reason after 48 attempts or so a dot is forcibly echoed to the screen!? why? I do not know. here's the code, its just a nested do while loop..thanks for any suggestions:
Code:
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include "conio.h"
#include <iomanip.h>
#include <string>
using namespace std;
char test[2][2];
void locate(int x, int y);
int main()
{
int chrs=0;
int y=0;
int bounds=0;
int dots[3];
int dot_count=0;
do {
int x=0;
do{
chrs=chrs+x;
test[y][x]=getche();
if (test[y][x] == '.')
{dots[dot_count]=x;
dot_count++;} //move this line and you can never
//enter a dot as the first character!
if (test[y][0]=='.'){
test[y][x]= ' ';
locate(chrs,0);
cout << ' ';
locate(chrs,0);}
else
x++;
if (x > 0)
bounds=x-1;
else
bounds=0;
}while ((x<=2) && (test[y][x-1] != '.'));
chrs=chrs+x-1;
y++;
cout << y;
}while (y<=2); system("PAUSE");
return 0;
}
void locate(int x, int y)
{
COORD point;
point.X = x; point.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), point);
}