- Syntax: typedef struct <name> { /*definition*/ } Synonyms
- Keyword : typedef , struct
- การสร้างอาเรย์ของ struct เหมือนการสร้างอาเรย์ทั่วไป
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <string.h> | |
typedef struct student | |
{ | |
char name[20] ; | |
int id; | |
} Student; | |
int main(void) | |
{ | |
char student[][20] = { "David", | |
"Ben" , | |
"Mark" , | |
"Tom" , | |
"Elizabeth" , | |
"Peter" | |
}; | |
int i; | |
// typedef int Age; | |
Student std[6]; | |
//struct student std[6]; | |
for(i= 0 ; i < 6 ; i++) | |
{ | |
strcpy(std[i].name,student[i]); | |
//std[i].name = student[i]; | |
std[i].id = i + 100; | |
} | |
for(i = 0 ; i < 6 ; i++) | |
{ | |
printf("%s , %d\n",std[i].name, std[i].id); | |
} | |
return 0; | |
} |