【问题标题】:Expression must have a pointer-to-object type error in an array表达式在数组中必须有指向对象类型错误
【发布时间】:2021-02-23 04:25:32
【问题描述】:
#include <stdio.h>
#define DIM 10

typedef struct{
    int nelem; //amount of numbers in the array
    int vector[DIM];
}t_vector_int;

int main(){
    t_vector_int vect={5,{3, 23, 56, 109, 238}};
    int n, i=0;

    printf(" Vector inicial: 3, 23, 56, 109, 238\n\nIntroduzca un valor entero: ");
    scanf("%d", &n);
    while(vect[i] <= n){

    }

    return 0;
}

我在第 15 行得到错误 while(vect[i] &lt;= n){,我知道这是因为 vect 被定义为 {5,{3, 23, 56, 109, 238}},但我真的不知道如何检查 n 是否属于 vect。

【问题讨论】:

    标签: arrays c structure


    【解决方案1】:

    您需要使用成员vector,而不是结构变量本身。

    改变

     while(vect[i] <= n)
    

    while(vect.vector[i] <= n)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 2015-06-11
      • 1970-01-01
      相关资源
      最近更新 更多