วันเสาร์ที่ 27 มิถุนายน พ.ศ. 2552

DTS02-23-06-2552

ความหมายของ Structure
หรือโครงสร้าง คือ กลุ่มของข้อมูลที่มีชนิดเหมือนกัน
หรือต่างกันก็ได้ซึ่งนำมารวมกลุ่มแล้วเรียกเป็นชื่อเดียวกัน


Structure มีประโยชน์มากในการสร้างและจัดการโครงสร้างข้อมูลที่ซับซ้อน
ประเภทของตัวแปร
• ตัวแปรเดี่ยว คือตัวแปรที่ขณะใดขณะหนึ่ง จะเก็บข้อมูลได้ค่าเดียว เช่น
– char ch1;
– int x;
• ตัวแปรชุด คือตัวแปรที่เก็บข้อมูลประเภทเดียวกัน ได้หลายค่า เช่น
– int num[ ] = {5, 7, 1, 18, 20};
– float f[10];
• ตัวแปรชนิด Structure คือตัวแปรที่สามารถเก็บข้อมูลหลายประเภท ภายใต้ชื่อเดียวกัน
การประกาศชนิดข้อมูลแบบ Structure

งานเขียนStructure
#include
#include
int main(void)
{
struct mp5
{
char Series[20];
int display;
char Support_file[30];
char Memory_type[20];
char Record_sound[20];
char Color[20];
float Price;
char Type_picture[30];
}

product;
strcpy(product.Series,"JXD318");
product.display=3;
strcpy(product.Support_file,"MP3,WMA,WAVFLAC,APE,VOB,DAT,MPG");
strcpy(product.Memory_type,"Memory 4Gb");
strcpy(product.Record_sound,"AAC format");
strcpy(product.Color,"16M colors");
product.Price=3500;
strcpy(product.Type_picture,"JPEG slide show zoom");
printf(" Product Series MP5\n\n");
printf(" Series:%s\n display:%d\n Support_file:%s\n Memory_type:%s\n Record_sound:%s\n Color:%s\n Price:%2f\n Type_picture:%s\n",
product.Series,product.display,product.Support_file,product.Memory_type,product.Record_sound,product.Color,product.Price,product.Type_picture);
return 0;
}