您的位置:

c语言编程195讲,c语言197%c

本文目录一览:

c语言 编程

#include stdio.h

/*

3、用一维数组解如下问题:读取20个在10到100之间的不重复的整数。每读取一个值时,如果它与已读取的值

不重复,就打印该值。用尽可能小的数组解决这个问题。

*/

void noRepeat() {

int a[20];

int i;

int j;

int count = 0;

printf("\n请输入20个10-100的整数:\n");

for (i=0; i20; i++) {

scanf("%d",a[count]);

if (a[count]10 || a[count]100) {

printf("输入错误!\n");

i--;

continue;

}

for (j=0; jcount; j++) {

if (a[count] == a[j]) {

break;

}

}

if (j == count) {

printf("[%d]\n",a[count]);

count++;

}

}

}

/*

5、Eratoshenes筛选是一种寻找素数的方法,该方法表述如下:

1)创建一个一维数组,把所有的元素初始化为1(表示真),下标为素数的元素保持1不变,其它下标的元素

最终被置为0

2)从数组下标2出发,每次发现值为1的数组元素时,则看其后的所有元素,把下标是它们倍数的那些元素置

为0。例如,对下标2来说,凡是2的倍数的下标(4,6,8,10,···)都将其元素置为0,对下标3来说,

凡是否的倍数的下标(6,9,12,15,···)将其元素置为0。

当以上过程结束后,仍为1的数组元素的下标就是素数,将这些下标打印输出即可。编写程序,

用含有1000个元素的数组确定并打印出1~999之间的所有素数

*/

void Eratoshenes() {

int a[1000];

int i;

int j;

for (i=2; i1000; i++) {

a[i] = 1;

}

for (i=2; i1000; i++) {

if (a[i] == 1) {

for (j=2; j*i1000; j++) {

a[j*i] = 0;

}

}

}

for (i=2; i1000; i++) {

if (a[i] == 1) {

printf("%d ",i);

}

}

}

/*

7、学生成绩统计。某班共6名学生,学习6门功课(数学分析,高等代数,大学物理,计算导论,经济学,英语),

每门功课有平时,期中和期末三项成绩,按平时占20%,期中占30%,期末占50%,求每人每门功课的平时成绩和

各个人6门功课的平均成绩及总平均成绩,最后要求按各人平均成绩的高低排序并打印成表格

*/

void func_average(int s[6][6][3], int a[6]){

int i;

int j;

float temp;

for (i=0; i6; i++) {

temp = 0;

for (j=0; j6; j++) {

temp += s[i][j][0] * 0.2f + s[i][j][1] * 0.3f + s[i][j][2] * 0.5f;

}

a[i] = (int)(temp / 6);

}

}

void func_score() {

int score[6][6][3] = {

{{10,10,10},{10,10,10},{10,10,10},{10,10,10},{10,10,10},{10,10,10}},

{{20,20,20},{20,20,20},{20,20,20},{20,20,20},{20,20,20},{20,20,20}},

{{30,30,30},{30,30,30},{30,30,30},{30,30,30},{30,30,30},{30,30,30}},

{{40,40,40},{40,40,40},{40,40,40},{40,40,40},{40,40,40},{40,40,40}},

{{50,50,50},{50,50,50},{50,50,50},{50,50,50},{50,50,50},{50,50,50}},

{{60,60,60},{60,60,60},{60,60,60},{60,60,60},{60,60,60},{60,60,60}}

};

char name[6][20] = {"abc","xyz","def","ghi","aaa","bbb"};

int average[6] = {0};

int index[6];

int i;

int j;

int temp;

func_average(score,average);

for (i=0; i6; i++) {

index[i] = 0;

for (j=0; j6; j++) {

if (average[index[i]]!=-1 average[j]=average[index[i]]) {

index[i] = j;

}

}

average[index[i]] = -1;

}

func_average(score,average);

for (i=0; i6; i++) {

printf("%4s",name[index[i]]);

for (j=0; j6; j++) {

temp = (int)(score[index[i]][j][0] * 0.2f +

score[index[i]][j][1] * 0.3f + score[index[i]][j][2] * 0.5f);

printf("%3d",temp);

}

printf("%3d\n",average[index[i]]);

}

}

/*

8、已知一个有限输入字符集合?={a,b},写一个程序能够识别集合L={anbn:0≤n≤N}。

说明:该问题实质上是判定输入字符串是否呈现aa ··· abb ··· b (a,b均为n个) 。

设字符串string有c个字符,则c=2n,且string[1]=··· =string[n]=a, string[n+1]= ···

=string[2n]=b (或进一步有这样的关系string[1],string[2]··· ,string[n]={a}, string[n+1],

string[n+2],··· ,string[2n]={b})。

*/

void f(char *str) {

int i = 0;

int j = 0;

char a;

char b;

char *p;

a = str[0];

for (i=0,p=str; *p!=0; p++,i++) {

if (a != *p) {

b = *p;

break;

}

}

for (j=0; *p!=0; p++,j++) {

if (b != *p) {

printf("不属于集合!\n");

return;

}

}

if (i == j) {

printf("属于集合!\n");

} else {

printf("不属于集合!\n");

}

}

void main() {

// Eratoshenes();

// noRepeat();

// func_score();

f("cccdddcc");

}

程序在vc6.0下调试通过.

C语言程序编程

1.编写一个程序它的功能是;打印出1到1000之内的能被7或11整除,但不能同时被7和11整除的所有数

#includestdio.h

void main(void)

{

int i,j;

for(i=1,j=0;i1000;i++)

{

if((!(i%7)||!(i%11))(i%77))

{

printf("%d\t",i);j++;

if(!(j%8)) printf("\n");

}

}

}

2.编写一个程序其功能是;将两个数位的整数放在C中并合并的方式是;将A的十位和个位依次放在C数的百位和个位,例如;当A=45,B=15

得到的结果是C=4515

你的第2题表达不清,我按照自己的理解给你写了一个,如果不行你要把题目的意思说清楚我才能做。

#includestdio.h

void main(void)

{

int a,b,c,flag;

do{

flag=0;

printf("请输入a,b(两位整数):");

scanf("%d%d",a,b);

if(a0||b0||a100||b100)

{

flag=1;

printf("对不起,你输入错误,请重新输入.\n");

}

}while(flag==1);

c=a*100+b;

printf("c=%d\n",c);

}

3.编写一个程序其功能是;计算并输出下列多项式值;

Sn=1+1/1!+1/2!+1/3!+1/4!+........+1/n!如主函数键盘给n输入15输出为S=2.718282

#includestdio.h

int mul(int x);

void main(void)

{

double SN=1.0f;

int i,N;

scanf("%d",N);

if(N=0) printf("对不起,请确保N=1\n");

for(i=1;i=N;i++)

SN+=1.0/mul(i);

printf("SN=%lf\n",SN);

}

int mul(int x)

{

int i,y;

if(!x) return 1;

for(i=1,y=1;i=x;i++)

y*=i;

return y;

}

4.编写一个程序其功能是;判断一个数是不是回文数(所谓回文数是指,从左到右读和从右到左读是同一样的结果)如;121是回文数而

1211就不是

#includestdio.h

#includestdlib.h

void main(void)

{

int x,y;

scanf("%d",x);

if(x0)

{

printf("输入错误!\n");

exit(-1);

}

y=x;

int i,j,k;

for(i=1,k=0;x!=0;x/=10)

{

j=x%10;

k=k*10+j;

}

if(y==k) printf("%d是回文数\n",y);

else printf("%d不是回文数\n",y);

}

5.编写一个程序其功能是;完成5个数的大到小的排序.如;1,2,3,4,5输出接个是5,4,3,2,1

#includestdio.h

#includestdlib.h

void main(void)

{

int i,j,k,a[5];

i=0;

do

{

printf("请输入第%d个数:",i+1);

scanf("%d",a+i);

i++;

}while(i5);

for(i=0;i5;i++)

for(j=i;j5;j++)

{

if(a[i]a[j])

{

k=a[i];

a[i]=a[j];

a[j]=k;

}

}

for(i=0;i5;i++)

printf("%d\t",a[i]);

}

C语言程序编写!

鄙人大一时的课程设计

/*TopBoy出品,品质保证*/

/*如果编译失败可将第一句#includemalloc.h改为#includealloc.h*/

#includemalloc.h

#includectype.h

#include graphics.h

#include stdio.h

#include conio.h

#define NULL 0

#define F10 17408

#define LEFT 0x4b00

#define RIGHT 0x4d00

#define DOWN 0x5000

#define UP 0x4800

#define SPACE 0x3920

#define ESC 0x011b

#define ENTER 0x1c0d

#define LEN sizeof(struct student)

struct student *insert(struct student *head);

struct student *print(struct student *head);

struct student *change(struct student *head,int);

struct student *del(struct student *head,int);/*删除记录*/

struct student *search(struct student *head);

void stat(struct student *head);

void save(struct student *head);

void printrecord(struct student *head);

void menuinit(void);

struct student *order(struct student *head);

struct student

{

long num;

char name[20];

char sex[7];

int score;

struct student *next;

};

int n; /*记录总数*/

int x=1,y=1,max;/*x表示显示记录的页数 y表示该页第y个记录*/

char *menutext[]={"Order",

"Insert",

"Change",

"Delete",

"Search",

"Statis",

"Quit"};

void init(void) /* 图形初始化 */

{

int gd=DETECT,gm;

initgraph(gd,gm,"");

}

void screeninit()

{

int i;

window(1,2,80,25);

textbackground(BLUE);

textcolor(7);

clrscr();

gotoxy(1,2);

putch(0xc9);/*输出左上角边框┏*/

for(i=1;i79;i++)putch(0xcd); /*输出上边框水平线*/

putch(0xbb); /*输出右上角边框 ┓*/

for(i=3;i24;i++)

{

gotoxy(1,i);putch(0xba); /*输出左垂直线*/

gotoxy(80,i);putch(0xba); /*输出右垂直线*/

}

gotoxy(1,24);putch(0xc8); /*输出左下角边框┗*/

for(i=1;i79;i++)putch(0xcd); /*输出下边框水平线*/

putch(0xbc); /*输出右下角边框┛*/

textbackground(7);

textcolor(BLACK);

window(1,25,80,25);

clrscr();

cputs(" You can press F10 to use Menu or ESC to quit.");

}

int chooseab(int locx,int locy,char str1[],char str2[])

{

int i,text1=4,text2=14,back1=15,back2=1,key;

while(1)

{

window(locx,locy,locx+strlen(str1)-1,locy);

textbackground(back1);textcolor(text1);

clrscr();gotoxy(1,1);printf("%s",str1);

window(locx+strlen(str1)+3,locy,locx+strlen(str1)+strlen(str2)+2,locy);

textbackground(back2);textcolor(text2);clrscr();gotoxy(1,1);printf("%s",str2);

key=bioskey(0);

if(key==LEFT||key==RIGHT)

{

i=text1;text1=text2;text2=i;

i=back1;back1=back2;back2=i;

}

else if(key==ENTER)break;

}

window(59,5,74,20);

if(text1==4)return 1;

else return 2;

}

void menuinit()

{

int i;

window(1,1,80,1);

textbackground(7);

textcolor(BLACK);

clrscr();

for(i=0;i7;i++)

{

gotoxy(i*10+5,1);

cprintf("%s",menutext[i]);

}

}

struct student *menu(struct student *head,int choose)

{

int i=0,ii=0,key;

window(1,1,80,1);

gotoxy(i*10+5,1);

textbackground(BLACK);

textcolor(WHITE);

cprintf("%s",menutext[i]);

for(;;)

{

switch(key)

{

case LEFT:

{

ii=i-1;

if(ii0)ii=6;

break;

}

case RIGHT:

{

ii=i+1;

if(ii6)ii=0;

break;

}

}

gotoxy(i*10+5,1);

textbackground(7);

textcolor(BLACK);

cprintf("%s",menutext[i]);

gotoxy(ii*10+5,1);

textbackground(BLACK);

textcolor(WHITE);

cprintf("%s",menutext[ii]);

i=ii;

key=bioskey(0);

if(key==ESC)

{

gotoxy(i*10+5,1);

textbackground(7);

textcolor(BLACK);

cprintf("%s",menutext[i]);

break;

}

if(key==ENTER)

{

switch(i)

{

case 0:head=order(head);break;

case 1:head=insert(head);break;

case 2:change(head,choose);break;

case 3:head=del(head,choose);break;

case 4:search(head);break;

case 5:stat(head);break;

case 6:save(head);break;

}

menuinit();

printrecord(head);

break;

}

}

window(2,3,78,23);

textbackground(BLUE);

textcolor(YELLOW);

return(head);

}

int aboutpro()

{

int i;

window(58,4,78,23);

textbackground(BLUE);

textcolor(YELLOW);

clrscr();

putch(218);

for(i=3;i20;i++)putch(196); /*输出上边框水平线*/

putch(191);

for(i=2;i20;i++)

{

gotoxy(1,i);putch(179); /*输出左垂直线*/

gotoxy(19,i);putch(179); /*输出右垂直线*/

}

gotoxy(1,19);putch(192);

for(i=3;i20;i++)putch(196);

putch(217);

gotoxy(3,4);cputs("Version:V2.0");

gotoxy(3,6);cputs("Author:");

gotoxy(3,7);cputs("Zhang Shou Song");

gotoxy(5,9);cputs("NEU C.S. 053");

window(1,1,80,1);

}

struct student *order(struct student *head)

{

struct student *p,*q,*t,*h1;

h1=head-next;

head-next=NULL;

while(h1!=NULL)

{

t=h1;

h1=h1-next;

p=head;

q=head;

while(t-scorep-scorep!=NULL)

{

q=p;

p=p-next;

}

if(p==q)

{

t-next=p;

head=t;

}

else

{

t-next=p;

q-next=t;

}

}

return head;

}

struct student *insert(struct student *head)

{

struct student *p0,*p1,*p2;

window(59,5,74,20);

textbackground(BLUE);

textcolor(YELLOW);

while(1)

{

clrscr();

p0=head;

p1=(struct student *)malloc(LEN);

gotoxy(5,1);printf("Insert");

gotoxy(1,3);printf("Quit by num=0");

gotoxy(1,5);printf("number:");

scanf("%ld",p1-num);

if(p1-num==0)break;

gotoxy(1,6);printf("name:");

scanf("%s",p1-name);

gotoxy(1,7);printf("sex:");

scanf("%s",p1-sex);

do{

gotoxy(1,8);printf("score:");

scanf("%d",p1-score);

}while(p1-score0||p1-score100);

if(head==NULL)

{

head=p1;

p1-next=NULL;

}

else

{

while((p1-scorep0-score)(p0-next!=NULL))

{

p2=p0;

p0=p0-next;

}

if(p1-score=p0-score)

{

if(head==p0)head=p1;

else p2-next=p1;

p1-next=p0;

}

else

{

p0-next=p1;

p1-next=NULL;

}

}

n++;

}

aboutpro();

clrscr();

return(head);

}

void printrecord(struct student *head)

{

struct student *p;

int i,j;

window(3,7,51,21);

textbackground(BLUE);

textcolor(YELLOW);

clrscr();

p=head;

for(i=1;ix;i++) /*处理分页*/

for(j=0;j15;j++)

p=p-next;

y=1;max=1;

if(head!=NULL)

do

{ gotoxy(3,y);

printf("%-8d%-9ld%-16s%-8s%-7d\n",y+(x-1)*15,p-num,p-name,p-sex,p-score);

p=p-next;

y++;

max=y-1;

if(y15)

{

max=15;

break;

}

}while(p!=NULL);

window(2,3,78,23);

}

void searchresult(struct student *p)

{

window(4,7,50,20);

textbackground(BLUE);

textcolor(YELLOW);

if(y==1)clrscr();

gotoxy(2,y);

printf("%-8d %-9ld%-16s%-8s%-7d\n",y,p-num,p-name,p-sex,p-score);

}

struct student *chooserecord(struct student *head)

{

int locate=1,key;

gotoxy(2,locate+4);putch(16);gotoxy(2,locate+4);

for(;;)

{

switch(key)

{

case UP:

{

locate--;

if(locate1n=15)locate=max;

if(locate1n15)

{

x--;

if(x1)x=n/15+1;

printrecord(head);

locate=max;

}

break;

}

case DOWN:

{

locate++;

if(locatemaxn=15)locate=1;

if(locatemaxn15)

{

x++;

if(x(n/15+1))x=1;/*判断是否到达页尾*/

locate=1;

printrecord(head);

}

break;

}

case F10:{head=menu(head,locate+(x-1)*15);break;}

}

putch(0);

gotoxy(2,locate+4);putch(16);gotoxy(2,locate+4);

key=bioskey(0);

if(key==ESC)save(head);

}

}

struct student *print(struct student *head)

{

window(2,3,78,23);

gotoxy(3,1);printf("******************** Student's Score Manage System **********************\n");

gotoxy(3,2);printf("| record | number | name | sex | score |\n");

gotoxy(3,3);printf("|--------|--------|---------------|-------|-------|\n");

printrecord(head);

chooserecord(head);

}

struct student *change(struct student *head,int choose)

{

struct student *p;

long stunum;

int i,key;

window(59,5,74,20);

textbackground(BLUE);

textcolor(YELLOW);

clrscr();

gotoxy(5,1);printf("Change");

p=head;

for(i=1;ichoose;i++)p=p-next;

gotoxy(1,3);printf("input new name:");

gotoxy(1,4);scanf("%s",p-name);

gotoxy(1,5);printf("input new sex:");

gotoxy(1,6);scanf("%s",p-sex);

gotoxy(1,7);printf("input new score:");

gotoxy(1,8);scanf("%d",p-score);

gotoxy(2,10);printf("Change Success!\n");

getch();

aboutpro();

clrscr();

return(head);

}

struct student *del(struct student *head,int choose)/*删除记录*/

{

struct student *p,*q;

long stunum;

int i;

window(59,5,74,20);

textbackground(BLUE);

textcolor(YELLOW);

clrscr();

q=p=head;

for(i=1;ichoose;i++)

{

q=p;

p=p-next;

}

gotoxy(5,1);printf("Delete");

gotoxy(1,3);printf("Are you sure");/*确认信息*/

gotoxy(2,4);printf(" to delete it?");

if(chooseab(62,11,"Yes","No")==1)

{

if(p==head)head=p-next;

else q-next=p-next;

free(p); /*释放内存*/

n--;

}

aboutpro();

clrscr();

return(head);

}

struct student *search(struct student *head)

{

struct student *p;

long stunum;

char *stuname;

int i,ii,score1,score2,key;

char *searchwith[]={"num","name","score"};

y=1;max=0;

window(59,5,74,20);

textbackground(BLUE);

textcolor(YELLOW);

clrscr();

textbackground(BLUE);

textcolor(YELLOW);

for(i=1;i3;i++)

{

gotoxy(i*5+2,2);

cprintf("%s",searchwith[i]);

}

gotoxy(2,2);

textbackground(RED);

textcolor(WHITE);

cprintf("%s",searchwith[0]);

i=0;ii=0;

key=0;

while (1)

{

switch(key)

{

case LEFT:

{

ii=i-1;

if(ii0)ii=2;

break;

}

case RIGHT:

{

ii=i+1;

if(ii2)ii=0;

break;

}

}

gotoxy(i*5+2,2);

textbackground(BLUE);

textcolor(YELLOW);

cprintf("%s",searchwith[i]);

gotoxy(ii*5+2,2);

textbackground(RED);

textcolor(WHITE);

cprintf("%s",searchwith[ii]);

i=ii;

key=bioskey(0);

if(key==ESC)

{

gotoxy(i*10+5,1);

textbackground(7);

textcolor(BLACK);

cprintf("%s",searchwith[i]);

break;

}

if(key==ENTER)

{

switch(i)

{

case 0:

{

gotoxy(1,5);printf("number:");

scanf("%ld",stunum);

p=head;

while(1)

{

while(p-num!=stunump!=NULL)p=p-next;

if(p==NULL)break;

else

{

searchresult(p);

y++;max++;

p=p-next;

}

}

break;

}

case 1:

{

gotoxy(1,5);printf("name:");

gotoxy(1,6);scanf("%s",stuname);

p=head;

while(1)

{

while(strstr(p-name,stuname)==NULLp!=NULL)p=p-next;

if(p==NULL)break;

else

{

searchresult(p);

y++;max++;

p=p-next;

}

}

break;

}

case 2:

{

gotoxy(1,5);printf("from score1:");scanf("%d",score1);

gotoxy(1,6);printf("to score2:");scanf("%d",score2);

p=head;

while(1)

{

while((p-scorescore1||p-scorescore2)p!=NULL)p=p-next;

if(p==NULL)break;

else

{

searchresult(p);

y++;max++;

p=p-next;

}

}

break;

}

}

break;

}

}

if(y==1){window(59,5,74,20);gotoxy(4,7);printf("Not Found");}

getch();

aboutpro();

clrscr();

}

void stat(struct student *head)

{

int i,j,begin=0,end=0,stutotal[5]={0,0,0,0,0};

int pointx1=50,pointy1=281,pointx2,pointy2;

char str[5];

struct student *p;

p=head;

for(i=0;in;i++)

{

if(p-score=0p-score60)stutotal[0]++;

else if(p-score=60p-score70)stutotal[1]++;

else if(p-score=70p-score80)stutotal[2]++;

else if(p-score=80p-score90)stutotal[3]++;

else if(p-score=90p-score=100)stutotal[4]++;

p=p-next;

}

init();

for(i=0;i4;i++) /*根据比例画扇形*/

{

setfillstyle(1,i+1);

begin=end; end=end+360*stutotal[i]/n;

pieslice(200,180,begin,end,100);

if(end==360)break;

}

if(end!=360)

{ setfillstyle(1,5);

pieslice(200,180,end,360,100);

}

rectangle(340,90,560,272);

settextstyle(0,0,1);

outtextxy(350,100,"color");/*显示图示的说明*/

outtextxy(410,100,"range");

outtextxy(500,100,"number");

outtextxy(400,132,"0 to 60:");

outtextxy(400,162,"60 to 70:");

outtextxy(400,192,"70 to 80:");

outtextxy(400,222,"80 to 90:");

outtextxy(400,252,"90 to 100:");

outtextxy(420,292,"total:");

sprintf(str,"%d",n);

outtextxy(520,292,str);

for(i=0;i5;i++)

{

sprintf(str,"%d",stutotal[i]);

outtextxy(520,132+i*30,str);

}

for(i=1;i=5;i++)

{

setfillstyle(1,i);

bar(350,100+i*30,380,110+i*30);

}

getch();

cleardevice();

setfillstyle(1,0); /*画折线图*/

bar(100,80,300,280);

line(50,281,280,281);

line(50,281,50,80);

outtextxy(60,285,"0-60");

outtextxy(105,285,"60-70");

outtextxy(150,285,"70-80");

outtextxy(195,285,"80-90");

outtextxy(250,285,"90-100");

for(i=0;i5;i++)

{ setfillstyle(1,i+1);

pointx2=pointx1+45; pointy2=280-200*stutotal[i]/n;

line(45,pointy2,50,pointy2);

sprintf(str,"%d",stutotal[i]);

outtextxy(30,pointy2,str);

line(pointx1,pointy1,pointx2,pointy2);

pointx1=pointx2;pointy1=pointy2;

}

line(45,80,50,80);

sprintf(str,"%d",n);

outtextxy(30,80,str);

outtextxy(30,280,"0"); getch();

closegraph();

screeninit();

window(2,3,78,23);

textbackground(BLUE);

textcolor(YELLOW);

clrscr();

gotoxy(3,1);printf("******************** Student's Score Manage System **********************\n");

gotoxy(3,2);printf("| record | number | name | sex | score |\n");

gotoxy(3,3);printf("|--------|--------|---------------|-------|-------|\n");

aboutpro();

clrscr();

}

void save(struct student *head)

{

FILE *fp;

int i;

struct student *p;

p=head;

fp=fopen("c:\\studin.txt","wb");

fprintf(fp,"zhangshousong"); /*将验证字符串写入文件*/

fprintf(fp,"\r\n"); /*将换行符号写入文件*/

fprintf(fp,"%d",n); /*将记录数写入文件*/

fprintf(fp,"\r\n"); /*将换行符号写入文件*/

for(i=0;in;i++)

{

fprintf(fp,"%-20ld%-30s%-10s%-10d",p-num,p-name,p-sex,p-score);/*格式写入记录*/

fprintf(fp,"\r\n"); /*将换行符号写入文件*/

p=p-next;

}

fclose(fp);

exit(0);

}

struct student *readdata()

{

FILE *fp;

int i;

char str[20]="zhangshousong",str2[20];

struct student *p,*q,*head;

p=(struct student *)malloc(LEN);

head=p;

if((fp=fopen("c:\\studin.txt","rb"))==NULL)/*打开文件*/

{

head=NULL;

n=0;

}

else

{

fscanf(fp,"%s",str2);

if(strcmp(str,str2)!=0)head=NULL;/*判断文件是不是合法的*/

else

{

fscanf(fp,"%d",n); /*读入记录数*/

if(n==0)head=NULL;

else

{

for(i=0;in;i++)

{

fscanf(fp,"%20ld%30s%10s%10d",p-num,p-name,p-sex,p-score); /*按格式读入记录*/

p-next=(struct student *)malloc(LEN);

q=p;

p=p-next;

}

q-next=NULL;

}

}

}

fclose(fp);

return head;

}

void main()

{

struct student *head;

int key=0,i;

init();

closegraph();

clrscr();

head=readdata();

menuinit();/*菜单初始化*/

screeninit();

window(2,3,78,23);

textbackground(BLUE);

textcolor(YELLOW);

clrscr();

aboutpro();

head=print(head);

}