ok, i'm making a game and i want it to have an arcade style name input function if you get a high score.
it needs to use the up and down keys to change the letter and then enter to accept and go to the next letter and it needs to be 3 characters long.
i have everything working fine but when i try to print the string after the name is input it also prints a couple of odd symbols after it.
i have no idea why it's doing this or how to fix it, any help would be greatly appreciated.
Heres the code:
Code:
#include <stdio.h>
#include <conio.h>
char change(char name,char a);
int main()
{
_setcursortype(_NOCURSOR);
char init[3],a;
int i;
init[0]='A';
init[1]='A';
init[2]='A';
textcolor(2);
cprintf("Please input your initials.\n\r");
for (i=0;i<3;i++)
{
a='a';
printf("%c",init[i]);
while (1)
{
if(kbhit())
{
a=getch();
init[i]=change(init[i],a);
gotoxy(i+1,2);
printf("%c",init[i]);
}
if (a=='\r')
break;
}
}
fflush(stdin);
printf("\n\n\n%s",init);
getch();
}
char change(char init,char a)
{
if (a=='H')
init++;
if (a=='P')
init--;
if (init=='@')
init='Z';
if (init=='[')
init='A';
return init;
}
Thanx in advance.
-----------------------
Windows XP.
borland c++ 5.00.