C语言程序强行停止

C语言程序强行停止,第1张

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#define N 30

typedef struct student

{

long number

char name[10]

float score[3]

float sum

float ave

} STUDENT

void swapfloat(float *x,float *y)

void swaplong(long *x,long *y)

void swapchar(char x[],char y[])

int main()

{

STUDENT stu[N]

int i,j,k,l,n

printf("请输入学生人数:")

scanf("%d",&n)

printf("请输竖罩滑入学号、姓名和各科成绩\n")

for(i=0i<ni++)

{

scanf("%ld,%s",&stu[i].number,stu[i].name)

stu[i].sum=0

for(j=0j<3j++)

{

scanf("%f",&stu[i].score[j])

stu[i].sum=stu[i].sum+stu[i].score[j]

}

stu[i].ave=stu[i].sum/3

}

char cx[10]

for(i=0i<n-1i++)

{

for(j=i+1j<nj++)

{

if(stu[j].sum>stu[i].sum)

{

for(k=0k<3k++)

{

swapfloat(&stu[j].score[k],&stu[i].score[k])

}

swapfloat(&stu[j].sum,&stu[i].sum)

swapfloat(&stu[j].ave,&stu[i].ave)

swaplong(&stu[j].number,&stu[i].number)

swapchar(stu[j].name,stu[i].name)

}

}

}

printf("请闷宴输入要查询余腊的学生姓名:")

scanf("%s",cx)

for(i=0i<ni++)

{

if(strcmp(cx,stu[i].name)==0)

printf("%s:%ld%6.1f%6.1f%6.1f 总分:%.1f,排名为第%d名\n",stu[i].name,stu[i].number,stu[i].score[0],stu[i].score[1],stu[i].score[2],stu[i].sum,i+1)

}

system("PAUSE")

return EXIT_SUCCESS

}

void swapfloat(float *x,float *y)

{

float temp

temp=*x

*x=*y

*y=temp

}

void swaplong(long *x,long *y)

{

long temp

temp=*x

*x=*y

*y=temp

}

void swapchar(char x[],char y[])

{

char temp[10]

strcpy(temp,x)

strcpy(x,y)

strcpy(y,temp)

}

C语言用exit()语句可以终止整个程序

C语言中,exit()通常是用在子程序中用来终结程序用的,使用后程序自动结束,跳回 *** 作系统。exit(0) 表示程序正常逗袭退出;exit(1)、exit(-1)表示程序异常退出。在整个程序中,只要调用exit,就会结束程序。

exit()函数所在的头文件是stdlib.h,需要将该头文件引入后使用。

扩展资料:

exit()函数内部实际 *** 作过程:

1、调用atexit()注册的函数(尺饥出口函数),按ATEXIT注册时相反的顺序调用所有由它注册的函数,这使得我们可以指定在程序终止时执行自己的清理动作.例如,保存程序状态信息于某个文山困兄件,解开对共享数据库上的锁等.

2、调用cleanup()来关闭所有打开的流,这将导致写所有被缓冲的输出,删除用TMPFILE函数建立的所有临时文件.

3、最后调用_exit()函数终止进程。

参考资料来源:百度百科-Exit()


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12422474.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-25
下一篇 2023-05-25

发表评论

登录后才能评论

评论列表(0条)

保存