資源簡介
在生成的同級目錄 增加 data.txt 其中為 抽獎人員名單
代碼片段和文件信息
//源代碼如下
#include??
#include??
#include??
#define?MAX_NUM?9999?
//定義保存人名和電話的數據結構?
struct?Person?
{?
char?name[20];?
char?telno[15];?
char?award;?
};?
int?num?=?0;?//統計人數?
FILE?*fp;?//文件指針?
Person?persons[MAX_NUM];?//定義數組?
int?awarder_1[1]?=?{-1};?//一等獎?
int?awarder_2[2]?=?{-1?-1};?//二等獎?
int?awarder_3[5]?=?{-1?-1?-1?-1?-1};//三等獎?
//讀取文件?
void?readdata()?
{?
int?i?=?0;?//數組下標?
Person?person;?
//文件打開?
fp?=?fopen(“data.txt“?“r“);?
if?(fp?==?NULL)?
{?
printf(“打開文件data.txt失敗!\n“);?
return;?
}?
//當文件不為空?
while?(!feof(fp))?
{?
num?++;?
fscanf(fp?“%s“?person.telno);?
fscanf(fp?“%s“?person.name);?
person.award?=?‘F‘;?
persons[i++]?=?person;?
}?
}?
//初始化標識?
void?init()?
{?
for(int?i?=?0;?i?{?
persons[i].awa
- 上一篇:c# 停車場管理系統源碼
- 下一篇:C#加密解密字符串源程序-后可直接使用
評論
共有 條評論