haubnerk
asked on
2 Part Question: elapsed time & writing data to a file in VC++
Hello, I am quite a beginner in the C++ arena, so bare with me.
1) I am trying to create a function that will collect a response time between hitting RETURN and typing the very first character of a sentence. (better explained below)
Example:
Hit RETURN or ENTER to begin (user hits the key)
Begin typing your sentence (printf statement)
(sentence 1) This is a test sentence <CR> (I want the timer
to collect the
the response time
as soon as <CR>
is hit.
(sentence 2) this is second sentence. (The timer stops
as soon as the
first character
of the next sente
is typed. In this
case, 't' is
typed in the word
'this')
Here is the code I have, but it's not quite working right. It is collecting the time it takes for the entire sentence to be typed instead of the interval between hitting return and typing the first character of the next sentence. I want
the user to eventually type in 5 sentences then go back to the main part of the program. and write this data (sentence and response time--see question 2)
void Do_Experiment(USHORT which) <<--(using switch() to get
{ here in main program)
if(which == 2)
{
clock_t begin, end;
clock_t *t=NULL;
double duration;
char buffer[80];
char character = '0';
int i, j=0;
printf("\nBegin typing your sentence. \n");
for(i =0; i <=5; i++)
{
while(scanf("\0", buffer));
end = NULL;
begin = clock();
gets(buffer);
if((character=getchar()) !='\n')
{
printf("character is... %c\n",character);
buffer[j]=character;
j++;
}
buffer[j-1]='\0';
printf("buffer is...%s\n",buffer);
end = clock();
duration = (double)(end-begin) / (double)CLOCKS_PER_SEC;
printf("\nThe response time was %1.4f\n",duration);
}
}
2) Next what I want to do is take the informatin that the user enters (the typed sentence) and the response time taken (see above) and write it to a file that can be viewed later for analysis.
If you need/want to see the entire program, please let me know via email: haubnerk@trac.wsmr.army.mi l
I would like to thank you in advance for anyone that can help me out.
1) I am trying to create a function that will collect a response time between hitting RETURN and typing the very first character of a sentence. (better explained below)
Example:
Hit RETURN or ENTER to begin (user hits the key)
Begin typing your sentence (printf statement)
(sentence 1) This is a test sentence <CR> (I want the timer
to collect the
the response time
as soon as <CR>
is hit.
(sentence 2) this is second sentence. (The timer stops
as soon as the
first character
of the next sente
is typed. In this
case, 't' is
typed in the word
'this')
Here is the code I have, but it's not quite working right. It is collecting the time it takes for the entire sentence to be typed instead of the interval between hitting return and typing the first character of the next sentence. I want
the user to eventually type in 5 sentences then go back to the main part of the program. and write this data (sentence and response time--see question 2)
void Do_Experiment(USHORT which) <<--(using switch() to get
{ here in main program)
if(which == 2)
{
clock_t begin, end;
clock_t *t=NULL;
double duration;
char buffer[80];
char character = '0';
int i, j=0;
printf("\nBegin typing your sentence. \n");
for(i =0; i <=5; i++)
{
while(scanf("\0", buffer));
end = NULL;
begin = clock();
gets(buffer);
if((character=getchar()) !='\n')
{
printf("character is... %c\n",character);
buffer[j]=character;
j++;
}
buffer[j-1]='\0';
printf("buffer is...%s\n",buffer);
end = clock();
duration = (double)(end-begin) / (double)CLOCKS_PER_SEC;
printf("\nThe response time was %1.4f\n",duration);
}
}
2) Next what I want to do is take the informatin that the user enters (the typed sentence) and the response time taken (see above) and write it to a file that can be viewed later for analysis.
If you need/want to see the entire program, please let me know via email: haubnerk@trac.wsmr.army.mi
I would like to thank you in advance for anyone that can help me out.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for the quick response, I will give this a try.
ASKER
myself.