我知道这是一个非常基本的问题,但是没有它我就无法继续前进,而且在其他地方也没有清楚地解释。
为什么这个编程给了我这么多未声明标识符的错误?不过,我已经宣布了。
这些是我得到的错误。
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);
}