Code:
#include <conio.h>
#include <stdio.h>
#include <string.h>
#include <dos.h>
#include <time.h>
void extview(int, int);
void main(){
FILE *fp;
int i;
int x=0;
int y=0;
int z=4;
int errcnt=0;
int cnt=0;
int spcnt=0;
float acc;
time_t start=0, end=0;
char str[650];
char ch;
clrscr();
fp=fopen("C:\\test.txt","rt");
fgets(str,650,fp);
extview(z, i);
/* Loop To Print The String */
for(i=0;i<strlen(str);i++){
gotoxy(10+(x++),5+y);
printf("%c", str[i]);
if ((i%50==0) && (i!=0)){
y+=3;
x=0;
}
}
x=0;
y=0;
ch=0;
/* Getting Input From The User & Highlighting Wrong Input */
for(i=0;i<strlen(str) && ch!=27;i++){
gotoxy(10+(x++), 6+y);
ch=getch();
if (start==0){
start=time(NULL);
}
cnt++;
textcolor(WHITE);
if (ch!=str[i]){
textcolor(RED);
if (ch==32) cprintf("%c", 24);
else cprintf("%c", ch);
sound(500);
delay(100);
nosound();
errcnt++;
}
else
printf("%c",ch);
if((i%50==0) && (i!=0)){
y+=3;
x=0;
}
}
/* Accuracy & WPM Calculation */
end=time(NULL);
cnt--;
errcnt--;
acc = (1.0*(cnt - errcnt) / cnt) * 100.0;
gotoxy(64,8);
printf("Accuracy: %.1f%", acc);
gotoxy(64,14);
printf("WPM: %.2f", (65/(difftime(end, start)/60)));
gotoxy(64,18);
printf("%d", spcnt);
getch();
}
void extview(int z, int i){
gotoxy(8,3);
printf("%c", 218);
for(i=0;i<53;i++){
printf("%c", 196);
}
gotoxy(62,3);
printf("%c", 191);
gotoxy(8,4);
for(i=0;i<40;i++){
printf("%c", 179);
gotoxy(8,z++);
}
z=4;
for(i=0;i<40;i++){
printf("%c", 179);
gotoxy(62,z++);
}
gotoxy(8,43);
printf("%c", 192);
gotoxy(62,43);
printf("%c", 217);
z=4;
gotoxy(9,43);
for(i=0;i<53;i++){
printf("%c", 196);
}
gotoxy(63,3);
printf("%c", 218);
gotoxy(63,4);
z=4;
for(i=0;i<40;i++){
printf("%c", 179);
gotoxy(63,z++);
}
gotoxy(63,43);
printf("%c", 192);
gotoxy(64,3);
for(i=0;i<16;i++){
printf("%c", 196);
}
gotoxy(80,3);
printf("%c", 191);
gotoxy(80,4);
z=4;
for(i=0;i<40;i++){
printf("%c", 179);
gotoxy(80, z++);
}
gotoxy(80,43);
printf("%c", 217);
gotoxy(64,43);
for(i=0;i<16;i++){
printf("%c", 196);
}
}
What I wanna do here is that after the text file is opened the number of spaces in the whole string (650 characters in total and 65 words) will be calculated. But I have no idea how to do that.