c - C中的结构

标签 c structure

这是一个读取和显示学生数据(姓名、出生日期、GPA)的程序。 我不明白问题出在哪里,它在 } 之前显示语法错误 token (第 14 行)和结构之前的语法错误(第 8 行)。有什么好的建议吗? 预先感谢您。

  #include<stdio.h>
  #include<stdlib.h>
  void main ()

  typeof struct
  {
    char name[10] ;
    date DOB ;
    float gpa;

  }
  student ;

  typeof struct
  {
      int day , month , year ;
  }
  date;

  printf("enter number of students n ");
  scanf("%d",&n);

  for(i=0;i<n;i++)
  {
     printf("enter student % data(name , date of birth & gpa )");
     scanf("%s%d%lf",i+1, &a[i].name , &a[i].DOB.day, &a[i].DOB.month,                   &a[i].DOB.year , &a[i].gpa);
  }

  for(i=0;i<n;i++)
  {
     printf("nmae : %s\t date of birth : %d \t gpa : %lf\t",i+1, a[i].name ,     a[i].DOB ,  a[i].gpa);
  }

最佳答案

您应该在 main 主体之外定义结构。

此外,typeof 不是您在定义结构时要使用的 C 构造。也许您想要 typedef

并且您的 main 缺少封闭的 {}

关于c - C中的结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20753274/

相关文章:

c - 如何在 C 中计算 2⁶⁴/n?

c - 读取txt,使用链表计算每个字母表

C - 循环,输入未正确读取,仅打印出 "no match"

c++ - WebKitGTK 中的 Ext JS webkit_web_view

Java:在类本身中创建多个对象实例或如何重组

c - C 允许函数调用作为参数吗?

c - 如何使用 C 将结构插入链表的节点?

c - ansi-c - 在结构中分配数组值

c - 存储在 EEPROM 中的数据结构的卷影副本

c - sizeof(struct) 不遵循填充