指標的用法

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>


int main()
{
      int i;
      struct classmate {int id; int h; int w; int d;};
      struct classmate *p;
      p=(struct classmate *)malloc(60*sizeof (struct classmate));
      for(i=0;i<2;i++)
      {
          printf("key in your ID:");
          scanf("%d",&p->id);       
          printf("key in your Height:");
          scanf("%d",&p->h);
          printf("key in your Weight:");
          scanf("%d",&p->w);
          printf("key in your Dosu:");
          scanf("%d",&p->d);
          
          printf("ID: %d\nHeight: %d\nWeight: %d\nDosu: %d \n",p->id,p->h,p->w,p->d);
          p++;
      }
     
      system("pause");
}

arrow
arrow
    全站熱搜

    Joy 發表在 痞客邦 留言(0) 人氣()