0
void capturat(i vec[5])

{ 

    float i; for (i=0;i<=5;i++)
    {
      printf("Dame los tiempos 5 maximo:\t");
      scanf("%f",&vec[i]);
    }
}

float imprimet(float vec[5])

{

     float i;
     for(i=0;i<5;i++)
        {
            printf("Tu tiempo es %f \n",vec[i]);
        }
}

The compiler says that I have an "array subscript is not an integer" in the functions capturat() and imprimet().

3
  • this line: void capturat(i vec[5]) is not valid, perhaps you meant: void capturat(float vec[5]) Commented Nov 16, 2015 at 16:13
  • for readability and understandability by us humans, only one statement per line. So this: float i; for (i=0;i<=5;i++) should be two lines. Commented Nov 16, 2015 at 16:15
  • when calling the system function: scanf(), always check the returned value (not the parameter value) to assure the operation was successful. In this case use: if( 1 != scanf("%f",&vec[i]) ) { perror("scanf() failed"); exit( EXIT_FAILURE ); } Where the 1 is the number of format specifiers in the format parameter Commented Nov 16, 2015 at 16:20

1 Answer 1

2

you should use integer for your loop counter i as array subscript has to be integer

int i; 
for (i=0;i<=5;i++)
{
    printf("Dame los tiempos 5 maximo:\t");
    scanf("%f",&vec[i]);
}
Sign up to request clarification or add additional context in comments.

1 Comment

Also warn the OP about his mistake on the loop test. The code invokes undefined behaviour.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.