我知道这是一个非常基本的问题,但是如果没有解决它,我就无法继续前进,而且其他地方也没有清楚地解释。
为什么我的编程会给我那么多未声明标识符的错误?虽然我已经声明了它。
以下是我收到的错误信息。
Error 2 error C2143: syntax error : missing ';' before 'type'
Error 3 error C2065: 'ptr' : undeclared identifier
Error 4 error C2065: 'contactInfo' : undeclared identifier
Error 5 error C2059: syntax error : ')'
Error 15 error C2223: left of '->number' must point to struct/union
以及更多...
#include<stdio.h>
#include<stdlib.h>
typedef struct contactInfo
{
int number;
char id;
}ContactInfo;
void main()
{
char ch;
printf("Do you want to dynamically etc");
scanf("%c",&ch);
fflush(stdin);
struct contactInfo nom,*ptr;
ptr=(contactInfo*)malloc(2*sizeof(contactInfo));
nom.id='c';
nom.number=12;
ptr->id=nom.id;
ptr->number=nom.number;
printf("Number -> %d\n ID -> %c\n",ptr->number,ptr->id);
}
stdin
上调用fflush
- 这是未定义的行为。 - Paul Rfflush
仅适用于输出或更新流 - 对于输入流,请使用fpurge
,或者只需调用getchar()
来丢弃不需要的字符。 - Paul R