Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/67.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C 持续错误:下标值既不是数组,也不是指针或向量_C_Pointers_Struct_Declaration - Fatal编程技术网

C 持续错误:下标值既不是数组,也不是指针或向量

C 持续错误:下标值既不是数组,也不是指针或向量,c,pointers,struct,declaration,C,Pointers,Struct,Declaration,我的大学作业有问题,我想得到一些帮助 有关守则的部分: #include <stdio.h> #include <stdlib.h> #define MAXSTRING 100 int counter = 0; int maxcounter = 0; int maxid = 0; typedef struct{ char name[MAXSTRING]; int id; }student; int AddStudent(student st, stu

我的大学作业有问题,我想得到一些帮助

有关守则的部分:

#include <stdio.h>
#include <stdlib.h>
#define MAXSTRING 100

int counter = 0;
int maxcounter = 0;
int maxid = 0;

typedef struct{
   char name[MAXSTRING];
   int id;
}student;


 int AddStudent(student st, student *stArray) {
     student t[] = {"",0};
     int id;
     char name[MAXSTRING];

     printf("First enter the student's id\n");
     scanf("%d", &id);
     printf("Now enter the student's name\n");
     scanf("%s", name[MAXSTRING]);

     if (st[maxcounter].id > maxid){
         maxid = t[maxcounter].id;
     }
     maxcounter++;
     t[maxcounter].id = id;
     t[maxcounter].name = name;
    printf("%d", t[maxcounter].id);
      }
你知道这是什么原因吗?我没有声明结构正确吗?

首先

  scanf("%s", name[MAXSTRING]);
这是错误的,应该是错误的

scanf("%99s", name);
这就是说,看看行中的用法

if (st[maxcounter].id > maxid){

错误,因为
st
定义为
student st
st
不是数组类型,因此不能对其使用索引,或者换句话说,不能将
st
用作
[]
运算符的操作数。

st
是函数的参数,它是
student
类型的单个值。因此,您不能按照错误所述为其下标<另一方面,code>t是
student
的数组

看看你的代码,你有

st[maxcounter].id > maxid
你可能是说

t[maxcounter].id > maxid

错误显示为
st
,而不是
t