Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7788887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:07:16+00:00 2026-06-01T21:07:16+00:00

I am getting a couple of weird compilation errors. This is for a homework

  • 0

I am getting a couple of weird compilation errors. This is for a homework assignment (help is ok). The idea is to implement a program that tests how well the user can hit “enter” once a second. I’m supposed to use gettimeofday to get some time values for each “enter” and then find out what the average time is and standard deviation… I’m trying to do this by checking stdin for ‘\n’ and then if true, using gettimeofday to populate a timeval struct, then store said struct in an array for later use…

The errors I’m getting when compiling (gcc -Wextra homework1.c) are:

homework1.c: In function ‘main’:
homework1.c:19:29: error: expected ‘]’ before ‘;’ token
homework1.c:27:17: error: expected ‘)’ before ‘;’ token
homework1.c:32:4: error: ‘entry_array’ undeclared (first use in this function)
homework1.c:32:4: note: each undeclared identifier is reported only once for each function it appears in

I can’t see why I’m getting those first two syntax errors and then I can’t understand why “entry_array” is undeclared when I am clearly declaring it in the beginning of “main.” Suggestions?

I feel like I’m getting burned by not knowing how to use the timeval struct… Initially I tried to define the struct timeval globally like you would with any other struct but was getting an error about overwriting the definition for struct timeval… Is this because it is defined in the “sys/time.h” library?

Here’s the code:

  GNU nano 2.2.6                        File: homework1.c                                                       
//prototypes 
int GetAverage(long array[]);
int GetStdDev(long array[]);

//# of keystrokes tracked by user
#define MAX_STROKES 1;



int main(int argv, char ** argc) {
        struct timeval entry_array[MAX_STROKES]; //container for tv_usec fields from timeval struct
        double average = 0; 
        double std_deviation = 0;
        int count = 0; 

        printf("This program will test your ability to hit enter every 1 second, for 10 seconds.  Ready when yo$

        //loop to build array of timeval's
        while (count < MAX_STROKES) {
                struct timeval time_val;
                int input = getc(stdin);
                if (input == '\n') {
                        gettimeofday(&time_val, NULL);
                        entry_array[count] = time_val;
                        ++count;
                }
        }
        return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T21:07:17+00:00Added an answer on June 1, 2026 at 9:07 pm

    The problem is the MAX_STROKES macro. As this is homework, I won’t tell you exactly what the problem with it is.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

getting a couple errors that it's a virtual function with non-virtual destructor. how can
I'm trying to nest a couple let statements, but I'm getting syntax errors that
I'm getting back into .NET development after a couple years and it seems that
I asked this a couple of days ago on Server Fault but am getting
update: After not getting anywhere with this, I noticed that when I pulled the
Well I'm having a couple problems getting google maps to work using the v3
I'm getting a couple of sql errors but I'm not too sure what to
Question asked a couple minutes ago gave me this idea... If you were to
These are my questions: I'm getting a couple of errors on the line public
This is kind of two questions in one :-D. I am getting a couple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.