c - 引用结构体值,但不断出现很多错误

标签 c struct compiler-errors

这是下面的代码。我在编译过程中不断收到很多错误,错误:取消引用指向不完整类型的指针 X1->数据 = X1->数据 + Y1->数据; 请帮忙。代码很简单,只有6种情况。基本上,我有两个寄存器,X 和 Y,以及一个保存命令和值的多维数组(1000 个内存位置)。因此,当用户键入命令 101 时,它会转到函数“First”,因此它是寄存器 X,并键入寄存器 X 的值,并且数组存储器将该值保存在位置 [1][1] 处,并且命令指向位置[1][0]。 102 用于寄存器 Y。

#include<stdlib.h>

#include<stdio.h>

#define SIZE 1000

int first(int *counter, struct registers* X1, int m[][2])
{
 int value;
 printf("Enter the value for the X\n");
 scanf("%d", &value);
 X1->data = value;
 m[*counter][0] = 101;
 m[*counter][1] = X1->data;
 *counter = *counter++;
 return 0;
}

int second(int *counter, struct registers* Y1, int m[][2])
{
 int value;
 printf("Enter the value for the Y\n");
 scanf("%d", &value);
 Y1->data = value;
 m[*counter][0] = 101;
 m[*counter][1] = Y1->data;
 *counter = *counter++;
 return 0;
}

int main()
{
 int memory[SIZE][2];
 int count = 0;
 int choice;
 struct registers
 {  
      int data;     

 } registerX, registerY;
 printf("Enter the instruction number:\n");
 scanf("%d", &choice);
 switch(choice)
 {
   case 101:
       first(&count, &registerX, memory);
   case 102:
       second(&count, &registerY, memory);
   default:
        printf("invalid code, please try again\n");
 }


} 

最佳答案

struct registers
 {  
      int data;     

 } . . . . .

这是main()的本地函数。在全局范围内定义它。

关于c - 引用结构体值,但不断出现很多错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27201841/

相关文章:

c - void * 函数指针

coldfusion - Cfhttp 结果结构在 CF8 中的行为就像 null 一样?

c++ - 结构位域最大大小(C99,C++)

compilation - 编译错误: hidden symbol `__aeabi_uidiv'

c - 如何从多线程并行的函数中获取一个正确的值

c++ - 使用 strstr() 函数正在破坏

c - 如何在处理信号时阻止相同的信号?

C4013 : undefined; assuming extern returning int

Java错误: cannot find symbol even if the .类文件都在同一目录中

c++ - 尝试使用RTools在R4.0上安装软件包时出现编译错误