프로그래머의 삶 Programmer's Life/C & C++

구조체 다시보기...

Oliver's World 2008. 11. 5. 11:33
728x90

#include<stdio.h>

struct student{
 int nb;
 char name[20];
}s[5];

struct student *ptr=s;
void print_s(struct student *ptr);

void main()
{
 int a;
 for(a=0;a<5;a++)
 {
  printf("Input school number : ");
  scanf("%d",&s[a].nb);
  printf("Input name : ");
  scanf("%s",&s[a].name);
 }
 print_s(ptr);
}

void print_s(struct student *ptr)
{
 int c;
 printf("\nStroged data \n");
 printf("Name\tSchoolNumber\n");
 for(c=0;c<5;c++)
 {
  printf("%s\t%d\n",ptr->name,ptr->nb);
  ptr++;
 }
}

728x90