[問題] C的結構問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
C
問題(Question):
書本範例: 利用學生ID搜尋,找出學生的資料
餵入的資料(Input):
#include<stdio.h>
struct mydata
{
int id;
char name[12];
int score;
}buffer;
int main(void)
{
FILE *fptr;
int idkey;
printf("Input ID to search");
scanf("%d",&idkey);
fptr=fopen("c:\\c_prog\\abc.txt","r");
if(fptr!=NULL)
{
while(!feof(fptr)&&(idkey!=buffer.id))
{
fread(&buffer,sizeof(buffer),1,fptr)
if(buffer.id==idkey)
{
printf("Yes! You got it!\n");
printf("Student's ID:%d\n",buffer.id);
printf("Student's NEME:%s\n",buffer.name);
printf("Student's score:%d\n",buffer.score);
}
}
}
...
...(以下省略
}
補充說明(Supplement):
程式打得有點多, 主要是想問為何 buffer.id 就可以找到資料
而不需要像 buffer[1].id 這樣呢?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 220.143.65.117
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1432525664.A.B13.html
→
05/25 11:59, , 1F
05/25 11:59, 1F
→
05/25 12:06, , 2F
05/25 12:06, 2F
→
05/25 12:08, , 3F
05/25 12:08, 3F
→
05/25 12:25, , 4F
05/25 12:25, 4F
→
05/25 13:06, , 5F
05/25 13:06, 5F
→
05/25 13:13, , 6F
05/25 13:13, 6F
→
05/25 13:14, , 7F
05/25 13:14, 7F
推
05/28 00:02, , 8F
05/28 00:02, 8F
討論串 (同標題文章)