ok, i rewrote my code, is this a better way of doing it?
Code:
#include <stdio.h>
#include <time.h>
void fillstring(char *s,char *keys,int size);
void typestring(char *s);
int error = 0;
int line = 0;
char home[] = "asdfghjkl;\'\"";
int range = sizeof(home)-1;
int main()
{
char string[16];
char *s;
s = string;
fillstring(s,home,range);
typestring(s);
}
void typestring(char *s)
{
char c;
system("cls");
printf("Typing Tutor 0.1\n");
printf("Type the following line:\n");
printf("\n%s\n",s);
do
{
while((c = getch()) != *s)
{
if(c == 'r')
{
fillstring(s,home,range);
typestring(s);
}
error++;
}
printf("%c",c);
s++;
}
while(*s);
line++;
if(line < 4)
{
fillstring(s,home,range);
typestring(s);
}
printf("\n");
printf("\nYou typed %i characters wrong!\n",error);
if(error > 5) printf("\n \rYou suck!");
printf("\nTry again? [y/n]");
c = getche();
if(c == 'y' || c == 'Y')
{
system("cls");
line = 0;
fillstring(s,home,range);
typestring(s);
}
else
exit(0);
}
void fillstring(char *s,char *keys,int size)
{
int i;
srand((unsigned)time(NULL));
for(i=0;i<16;i++) //fill string with home row characters
{
*(s+i) = keys[rand()%size];
while(*(s+i) == *(s+i-1)) //this loop keeps letters from repeating
*(s+i) = keys[rand()%size];
}
*(s+16) = '\0';
}