#include “stdafx.h”
#include “malloc.h”
#include “stdlib.h”
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef struct LNode{
int data;
int *next;
}LNode,*LinkList;
void GetElem_L(LinkList L,int i,int &e)//第i个元素值赋给e
{
int *p;
p=L->next;int j=1;
while(p&&j<i)
{
p=p->next;++j;//这儿报错,error C2227: left of “->next” must point to class/struct/union。应该怎么修改呀。
}
}
int main(int argc, char* argv[])
{
printf(“Hello World!\n”);
return 0;
}
#include “malloc.h”
#include “stdlib.h”
#define OK 1
#define ERROR 0
#define OVERFLOW -2
typedef struct LNode{
int data;
int *next;
}LNode,*LinkList;
void GetElem_L(LinkList L,int i,int &e)//第i个元素值赋给e
{
int *p;
p=L->next;int j=1;
while(p&&j<i)
{
p=p->next;++j;//这儿报错,error C2227: left of “->next” must point to class/struct/union。应该怎么修改呀。
}
}
int main(int argc, char* argv[])
{
printf(“Hello World!\n”);
return 0;
}
解决方案
10
int *next; // 应该struct LNode *next
int *p;
int *p;
60
#include "stdafx.h" #include "malloc.h" #include "stdlib.h" #define OK 1 #define ERROR 0 #define OVERFLOW -2 typedef struct LNode{ int data; LNode *next; }LNode,*LinkList; void GetElem_L(LinkList L,int i,int &e)//第i个元素值赋给e { LNode *p; p=L->next;int j=1; while(p&&j<i) { p=p->next;++j;//这儿报错,error C2227: left of "->next" must point to class/struct/union。应该怎么修改呀。 } } int main(int argc, char* argv[]) { printf("Hello World!\n"); return 0; }