📄 mis_sms(finish).c
字号:
int i;
GoToXY(0,0);
printf("%c",213);
for (i=0;i<30;i++)
printf("%c",205);
printf(" ");
for (i=0;i<30;i++)
printf("%c",205);
printf("%c",184);
GoToXY(0,13);
printf("%c",179);
GoToXY(79,13);
printf("%c",179);
}
/*
*************************************************************
* 函数描述:用户交互界面(窗体)的绘制函数
* 输入参数:无
* 返回值 :无
*************************************************************
*/
void PrintFrame()
{
int i,j;
PrintTopBorder();
GoToXY(0,1);
for (j=0;j<16;j++)
{
printf("%c",179);
for (i=0;i<78;i++)
printf(" ");
printf("%c",179);
}
printf("%c",195);
for (i=0;i<34;i++)
printf("%c",196);
printf(" Message ");
for (i=0;i<35;i++)
printf("%c",196);
printf("%c",180);
for (j=0;j<5;j++)
{
printf("%c",179);
for (i=0;i<78;i++)
printf(" ");
printf("%c",179);
}
printf("%c",192);
for (j=0;j<78;j++)
printf("%c",196);
printf("%c",217);
printf("verion 0127");
for(i=0;i<69;i++)
printf(" ");
}
/*
*************************************************************
* 函数描述:主菜单的绘制函数
* 输入参数:无
* 返回值 :无
*************************************************************
*/
void PrintMenu()
{
GoToXY(30,2);
printf("1.Add students'info");
GoToXY(30,3);
printf("2.Sort students");
GoToXY(30,4);
printf("3.Print student's report");
GoToXY(30,5);
printf("4.Save data to file");
GoToXY(30,6);
printf("5.Load data from file");
GoToXY(30,7);
printf("6.Search student");
GoToXY(30,8);
printf("7.Stat. data");
GoToXY(30,9);
printf("0.Exit");
GoToXY(30,11);
printf("Please make a choise[0-7]");
}
void Select()
{
GoToXY(13,12);
printf(" [1].Continue ");
GoToXY(13,13);
printf(" [0].Back to Menu");
}
/*
*************************************************************
* 函数描述:去除字符串左右空格函数
* 输入参数:str 指向字符串的指针
* 返回值 :处理后的字符串
*************************************************************
*/
char * Del_LeftRightSpace(char *str)
{
int len,i=0;
len = strlen(str);
while (str[0]==' ')
{
str++;
len--;
}
if (len != 0)
{
for (i=len-1;i>=0;i--)
{
if (str[i]!=' ')
break;
}
str[i+1]='\0';
}
else
str[0]='\0';
return str;
}
/*
*************************************************************
* 函数描述:去除字符串左右零函数
* 输入参数:str 指向字符串的指针
* 返回值 :处理后的字符串
*************************************************************
*/
char *LeftRightZero(char *str)
{
int len,i=0;
len = strlen(str);
while (str[0]=='0' && str[1]!='.')
{
str++;
len--;
}
for (i=0;i<len;i++)
if (str[i]=='.' && str[i+1]=='0')
{
str[i]='\0';
return str;
}
str[len]='\0';
return str;
}
/*
*************************************************************
* 函数描述:判断字符串是否是数字的函数
* 输入参数:str 指向字符串的指针
* 返回值 :是 返回1 否返回0
*************************************************************
*/
int IdentifyDigit(char *str)
{
int i;
for (i=0;i<strlen(str);i++)
if (isdigit(str[i]) == 0)
break;
if (i==strlen(str))
return 1;
else
return 0;
}
/*
*************************************************************
* 函数描述:判断字符串是否由数字和小数点组成的函数
* 输入参数:str 指向字符串的指针
* 返回值 :是 返回1 否返回0
*************************************************************
*/
int IdentifyNum(char *str)
{
int i;
for (i=0;i<strlen(str);i++)
{ if (isdigit(str[i]) == 0) //如果不是数字
if (str[i]!='.') //又不是小数点
break;
}
if (i==strlen(str))
return 1;
else
return 0;
}
/*
*************************************************************
* 函数描述:弹出错误警告的函数
* 输入参数:str 指向字符串的指针
* 返回值 :无
*************************************************************
*/
void ErrorAlart(char *str,char *str_error,int x,int y)
{
int i;
int lenlimit=20;
GoToXY(1,19);
printf("Error ,Your input %s have invalid string!!! ",str);
if (strcmp("name",str)==0 )
{
GoToXY(1,20);
printf("--Name only include [A-Z] and [space]");
}
if (strcmp("age",str)==0)
{
lenlimit=3;
GoToXY(1,20);
printf("--Age only between [10-20]--");
}
if (strcmp("grade",str)==0)
{
lenlimit=5;
GoToXY(1,20);
printf("--Grade only between [0.0-100]--");
}
if (strcmp("empty",str_error)==0)
{
Clear(1,20);
GoToXY(1,20);
printf("alert \"%s \" cant empty !!!",str);
}
GoToXY(1,21);
printf("Press any key to continue !!!");
GetchKey();
GoToXY(x,y);
for (i=0;i<lenlimit;i++)
{
printf(" ");
}
ClearMassage();
}
/*
*************************************************************
* 函数描述:判断字符串中小数点函数
* 输入参数:str 指向字符串的指针
* 返回值 :字符串合法返回小数点的下标,不合法返回0
*************************************************************
*/
int IdentifyPoint(char *str)
{
int i,j=-1,flag=0;
if (str[0]=='.')
{
if (str[1]=='5')
{
str[0]='0';
str[1]='.';
str[2]='5';
str[3]='\0';
return j;
}
else
return 0;
}
for (i=1;i<strlen(str);i++)
if (str[i] == '.')
{
j=i;
flag++; //每扫描到一个小数点flag++
}
if (flag>1) //flag>1说明有1个以上的小数点
return 0;
for (i=1;i<strlen(str);i++)
if (str[i]=='.')
{
if (str[i+1]=='\0')
{
str[i]='\0';
return j;
}
if (str[i+1]!='5'&& str[i+1]!='0')
return 0;
}
return j; //返回小数点的下标
}
/*
*************************************************************
* 函数描述:在指定坐标画矩形函数
* 输入参数:标题字符串
* 返回值 :无
*************************************************************
*/
void PrintTitle(char *str)
{
int j=0,i,len,space;
len=strlen(str);
if (len%2 == 0)
space=(20-len)/2;
else
{
space=(21-len)/2;
j=1;
}
GoToXY(30,0);
for (i=0;i<space;i++)
printf("%c",205);
printf("%s",str);
for (i=0;i<space;i++)
printf("%c",205);
}
/*
*************************************************************
* 函数描述:成绩输入函数
* 输入参数:str:指向成绩的存放位置
* subjecname: 进行输入的课程名
* space_len 空格长度 y 坐标点 用于调整位置
* 返回值 :无
*************************************************************
*/
int InputGrade(char *str,char *subjectname,char *space_len,int y)
{
int identify,i,len,inputcheck;
while(1)
{
len=-1;
GoToXY(30,y);
for (i=0;i<4;i++)
{
printf(" ");
}
GoToXY(1,19);
printf("%s Please Enter %s ",space_len,subjectname);
GoToXY(30,y);
inputcheck=GetString(str,4);
//inputcheck=InputDataCheck(str,4,30,y);
if (inputcheck == -1)
{
if (atoi(p->data.sno)==1)
head=NULL;
return -1;
}
if (inputcheck==EMPTY)
{
ClearMassage();
ErrorAlart("grade","empty",30,y);
continue;
}
strcpy(str,Del_LeftRightSpace(str)); //去左右空格
while (IdentifyNum(str))
{
identify=IdentifyPoint(str);
if (
identify==-1
||
(identify == 1 && strlen(str)<=3)
||
(identify == 2 && strlen(str)<=4)
||
(identify == 3 && strlen(str)<=5)
)
{
if (atof(str) == 0)
{
strcpy(str,"0");
len=strlen(str);
break;
}
if (atof(str) > 0.0 && atof(str) <= 100.00)
{
strcpy(str,LeftRightZero(str));
len=strlen(str);
break;
}
}
break;
} //end while
if (len==-1 || len==0)
{
ClearMassage();
ErrorAlart("grade","",30,y);
continue;
}
else
{
GoToXY(30,y);
printf(" ");
GoToXY(30,y);
printf("%s",str);
}
break;
}
return 1;
}
/*
*************************************************************
* 函数描述:文件写入函数
* 输入参数:文件名
* 返回值 :-1 返回MENU
*************************************************************
*/
int WriteData(char *fn)
{
if ((fp=fopen(fn,"wb"))==NULL)
{
ClearAll();
GoToXY(24,10);
printf("error,can not open file!!!");
GetchKey();
return -1;
}
in=head->next;
while (in->data.sno!=NULL)
{
fwrite(&in->data,sizeof(struct stu_info),1,fp);
in=in->next;
}
fclose(fp);
ClearAll();
GoToXY(26,10);
printf(" Record save successful!!");
filedatachange=0;
if (exitflag==1)
{
GoToXY(24,12);
printf("Press any key to Exit System!!!");
getch();
exit(0);
}
GoToXY(24,12);
printf("Press any key to back main menu!!!");
GetchKey();
return -1;
}
/*
*************************************************************
* 函数描述:文件名检查的函数
* 输入参数:文件名
* 返回值 :溢出、空、错误、合法
*************************************************************
*/
int IsValidFileName(const char *pFileName)
{
int nonDot = -1;
int dot = -1;
int len = 0;
static int isCharValid[32] =
{
// ' ' ! " # $ % & ' ( ) * + , - . /
1 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 1 , 1 , 0 ,
// 0 1 2 3 4 5 6 7 8 9 : ; < = > ?
1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 0 , 1 , 0 , 0
};
if (strlen(pFileName) > FILE_NAME_LIMIT) // 文件长度>8位
return ISVALID_FILENAME_OVERFLOW;
if (!pFileName || !*pFileName)//文件明为空
return ISVALID_FILENAME_EMPTY;
if (pFileName[0] == '.') //文件名第一个字符不能为'.'
return ISVALID_FILENAME_ERRORDOT;
for (; len < 256 && pFileName[len]; len++) //文件明是否包含非法字符
{
if (pFileName[len] >= '@')
{
if (pFileName[len] == '\\' || pFileName[len] == '|')
return ISVALID_FILENAME_ERROR;
}
if (pFileName[len] >= 32 && pFileName[len] <= 63)
{
if (isCharValid[pFileName[len] - 32] == 0)
return ISVALID_FILENAME_ERROR;
}
dot = len;
}//end for
return ISVALID_FILENAME_VALID;
} //end fuction
/*
*************************************************************
* 函数描述:文件载入函数
* 输入参数:无
* 返回值 :0
*************************************************************
*/
int LoadData()
{
Stu_Lnode *out,*outtail;
int key,flag;
int l_x,l_y;
ClearDisplay(1,1);
PrintTitle("load data");
if(savedatalabel == 1) //如果已经有文件被载入,并被修改 or 之前保存过的文件被修改
{
GoToXY(18,8);
printf("Alert,The data has been change,would you save??");
GoToXY(24,10);
if (loadfilename[0]!='\0')
{
printf("[1]. Yes (Save to file \" %s \")",loadfilename);
}
else
{
printf("[1]. Yes");
flag=1;
}
GoToXY(24,11);
printf("[2]. No");
GoToXY(24,12);
printf("[0]. Back to main menu");
GoToXY(24,14);
printf("Please make a choise[0-2]");
WhereXY(&l_x,&l_y);
while(1)
{
key = GetchKey();
if (key==_1||key==_2||key==_0||key==_ESC)
{
ClearDisplay(1,1);
break;
}
PrintAlert(2);
GoToXY(l_x,l_y);
}
switch(key)
{
case _1:
if (flag==1)
{
flag=SaveData();
savedatalabel=0;
return -1;
}
strcpy(fn,loadfilename);
WriteData(fn);
break;
case _2:
filedatachange=0;
break;
case _0:
case _ESC:
return -1;
}
}
GoToXY(24,10);
printf("Please Input file name:");
if (GetString(fn,8)==-1)
return -1;
strcpy(fn,Del_LeftRightSpace(fn));
if (!strcmp(fn,""))
{
Clear(1,10);
GoToXY(1,19);
printf("Error , file name cant empty!!!");
GoToXY(28,10);
printf("Press [ESC] back to menu!!!");
GoToXY(28,12);
printf("Press ANY KEY to continue");
if (GetchKey()==_ESC)
return -1;
return 0;
}
if ((fp1=fopen(fn,"r"))==NULL)
{
Clear(1,10);
GoToXY(1,19);
printf("error,can not open file!!! ");
GoToXY(28,12);
printf("Press [ESC] back to menu!!!");
GoToXY(28,14);
printf("Press ANY KEY to continue");
if (GetchKey()==_ESC)
return -1;
Clear(1,19);
return 0;
}
out = (Stu_Lnode *)malloc(sizeof(Stu_Lnode));
head = tail = (Stu_Lnode *)malloc(sizeof(Stu_Lnode));
head=out;
while (!feof(fp1))
{
outtail=out;
out->next = (Stu_Lnode *)malloc(sizeof(Stu_Lnode));
out=out->next;
out->pre = outtail;
fread(&out->data,sizeof(struct stu_info),1,fp1);
}
fclose(fp1);
tail=outtail;
tail->next=NULL;
strcpy(loadfilename,fn);
GoToXY(24,10);
printf("File load successful!!! ");
GoToXY(24,12);
printf("Press any key back to main menu");
GetchKey();
return -1;
}
/*
*************************************************************
* 函数描述:数据保存函数
* 输入参数:无
* 返回值 :-1 返回MENU
*************************************************************
*/
int SaveData()
{
int key;
int label=1,filename=ISVALID_FILENAME_VALID;
PrintFrame();
GoToXY(31,0);
printf("Save Student's Info");
if (tail->data.sno==NULL) //内存没有记录
{
GoToXY(28,10);
printf("Error There is no record");
GoToXY(28,12);
printf("Press any key to back menu");
GetchKey();
return -1; //返回MENU
}
if (strlen(loadfilename) != 0 ) //如果已经有文件被载入
{
GoToXY(28,10);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -