Я пишу небольшую небольшую программу как практику: ее можно добавить в векторы. Я получаю сообщение об ошибке из IDE, в котором говорится: «ошибка: индексированное значение не является ни массивом, ни указателем, ни вектором». Это происходит, когда я перехожу через цикл for и пользователь вводит некоторые данные типа float, используя функцию scanf(). Я отправлю код ниже, чтобы вы могли убедиться сами.Ошибка в коде, программирование на C
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
float xcomp;
float ycomp;
}vectors;
vectors initializeVector(vectors userVect, int length);
int main()
{
/* This block determines the amount of vectors that will be added.
It will then create an array of vector structs the size of the amount being added.
Afterwards it will call a function that will grab the users data (vector information) and use
to add the vectors in the array.*/
int amount;
printf("How many vectors would you like to add?\n");
printf("AMOUNT: ");
scanf("%d", &amount);
vectors myvect[amount];
initializeVector(myvect[amount],amount); //<-- This is a function call.
return 0;
}
vectors initializeVector(vectors userVect, int length)
{
/* This function will go through the array of vectors and allow the user
to input the components of each vector in the array.*/
printf("Enter the 'X' and 'Y' components of your vector\n");
int i;
for(i=0; i<length;i++)
{
printf("%d", i+1);
printf(" vector:\n");
printf("X: ");
scanf("%f", userVect[i].xcomp); // This line brings up the error
printf("\nY: ");
scanf("%f", userVect[i].ycomp); // this line brings up the error
}
}
Почему пометка [tag: C++] then? Re-Tagged ... –
векторы * userVect; userVect [я] -> xcomp; –
Поскольку параметр userVect не является массивом. Вы не можете индексировать его. – OldProgrammer