加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

C语言实现随机排座位程序

(2010-07-29 22:11:27)
标签:

it

分类: 我的C语言

 @author 振震
 Mail:xuzhenzhen654321@yeah.net
 QQ:865702942
 Call:15153411078

#include"stdio.h"
#include"dos.h"
#include"process.h"
#include"stdlib.h"
#include"time.h"
#define N 200
typedef struct
{
 char name[20];
 int zuowei;
} STU;
STU xuesheng[N];
int a[N];
void paixu(STU a[],int n)
{
 FILE *fp;
 char stu[10];
 int i=0,p;
 if((fp=fopen("student.txt","r"))==NULL)
 {
  printf("student file can't be opened\n");
  getchar();
  exit(1);
 }
 else
 {srand((unsigned)time(NULL));
 
  for(i=0;i<n;i++)
  {
   p=rand()%n;
   while(a[p].zuowei!=0)
   {
   p=rand()%n;
   }
   fscanf(fp,"%s",stu);
   a[p].zuowei=atoi(stu);
  }
 }
}
void mingzi(STU a[],int m)
{
 FILE *fp;
 int i;
 if((fp=fopen("mingzi.txt","r"))==NULL)
 {printf("mingzi file can't open\n");
 getchar();
 exit(1);}
 else
 {
  for(i=0;i<m;i++)
   fscanf(fp,"%s",a[i].name);
 }
}
void main()
{
 FILE *fp;
 int i;
 int m,n;
 printf("please input the students'number:");
 scanf("%d",&m);
 printf("please input the sits'number:");
 scanf("%d",&n);
 getchar();
 
 paixu(xuesheng,n);
 mingzi(xuesheng,m);
 if((fp=fopen("paizuo.txt","w+"))==NULL)
 {printf("paizuo file can't open\n");
 getchar();
 exit(1);}
 else
 {
  for(i=0;i<m;i++)
  {
   fprintf(fp,"%-20s%04d\n",xuesheng[i].name,xuesheng[i].zuowei);
  }
 }
 getchar();
}

 

 

 

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有