📄 student.c
字号:
}
temp=(struct student*)malloc(sizeof(struct student));
k++;
g_count++;
}
free(temp);
fread(num,400*sizeof(char),1,fp);
fread(&g_z,sizeof(int),1,fp);
}
fclose(fp);
return 1;
}
//////////////////////1.添加学生信息//////////////////////
void AddStudentInfo()
{
system("cls");
Addstu();
WinAddStudentInfo();
BuildStuId(); //自动生成和回收学号
InputStuName(); //输入姓名
temp->age=InputStuAge(); //输入年龄
goxy(35,8);
temp->grade[0]=InputStugrade(); //输入语文成绩
goxy(35,9);
temp->grade[1]=InputStugrade(); //输入英语成绩
goxy(35,10);
temp->grade[2]=InputStugrade(); //输入数学成绩
goxy(35,11);
temp->grade[3]=InputStugrade(); //输入物理成绩
goxy(35,12);
temp->grade[4]=InputStugrade(); //输入化学成绩
g_count++;
}
void Addstu()
{
if (head==NULL)
{
head=(struct student*)malloc(LEN);
head->pre=NULL;
tail=head;
}
temp=(struct student*)malloc(LEN);
temp->next=NULL;
temp->pre=tail;
tail->next=temp;
tail=temp;
}
struct student *addstudentinfo()
{
char str[1];
while (g_count<100)
{
AddStudentInfo();
g_sav = 0;
goxy(2,19);
printf("Enter successful, would you like to enter again?");
goxy(2,20);
printf("Please input Y(yes) or N(no):");
while(1)
{
goxy(31,20);
GetString(str,1);
if (str[0]=='Y'||str[0]=='y')
break;
else if (str[0]=='N'||str[0]=='n')
return head;
else
{
goxy(2,21);
putchar(str[0]);
printf(" is a error option,please input any ch to continue");
getch();
goxy(31,20);
printf(" ");
goxy(2,21);
printf(" ");
goxy(31,20);
}
}
}
goxy(2,21);
printf("The data is fulled,press any ch to continue");
getch();
return head;
}
///////////////////////自动生成学号/////////////////
void BuildStuId()
{
if (g_z<=0)
{
printf("%03d",g_count+1);
sprintf(temp->sno,"%03d",g_count+1);
}
if (g_z>0)
{
temp->sno[0]=num[g_z-1][0];
temp->sno[1]=num[g_z-1][1];
temp->sno[2]=num[g_z-1][2];
temp->sno[3]=num[g_z-1][3];
printf("%s",temp->sno);
g_z--;
if (g_count==0)
{
head=(struct student*)malloc(LEN);
tail=head;
}
}
}
//////////////////////输入学生姓名////////////////////////
void InputStuName()
{
int i,mark=0;
char str[21];
while(1)
{
goxy(35,6);
GetString(str,20);
ReMoveSpece(str,temp->name);
if (temp->name[0]==0) //判断是否空字符串
{
Blank();
continue;
}
for (i=0;i<(int)strlen(temp->name);i++) //判断是否字母和空格
{
if (!(isalpha(temp->name[i])||temp->name[i]==' '))
{
mark=1;
goxy(2,19);
printf("The name only can include letter,please enter a new name again:");
goxy(2,20);
printf("Please input any ch to continue");
getch();
goxy(2,19);
printf(" ");
goxy(2,20);
printf(" ");
goxy(35,6);
printf(" ");
break;
}
}
if (mark==1)
{
mark=0;
continue;
}
goxy(35,6);
printf(" ");
goxy(35,6);
printf("%s",temp->name);
break;
}
}
//////////////////////输入年龄/////////////////////
int InputStuAge()
{
int i,mark=0,stuage;
char str[3],str1[3];
while(1)
{
goxy(35,7);
GetString(str1,2);
ReMoveSpece(str1,str);
if (str[0]==0) //判断是否空字符串
{
Blank();
continue;
}
for (i=0;i<(int)strlen(str);i++) //判断是否数字
{
if (!isdigit(str[i]))
{
mark=1;
goxy(3,19);
printf("The age can't include letter,please input a age[10-20]:");
goxy(3,20);
printf("Please input any ch to continue");
getch();
goxy(35,7);
printf(" ");
goxy(3,19);
printf(" ");
goxy(3,20);
printf(" ");
break;
}
}
if (mark==1)
{
mark=0;
continue;
}
stuage=atoi(str);
if (stuage<7||stuage>50)
{
goxy(3,19);
if (stuage<7)
printf("Sorry,you input too small,the age between 7 to 50:");
else if(stuage>50)
printf("Sorry,you input too big,the age between 7 to 50:");
goxy(3,20);
printf("Please input anych to continue");
getch();
goxy(35,7);
printf(" ");
goxy(3,19);
printf(" ");
goxy(3,20);
printf(" ");
continue;
}
goxy(35,7);
printf(" ");
goxy(35,7);
printf("%d",stuage);
return stuage;
}
}
///////////////////////输入成绩//////////////////////
float InputStugrade()
{
struct position pos;
char subject[5],str[5];
int i=0,sign=0,stringlen,point=0;float result;
int x,y;
pos=GetCurentPos(); //获取当前光标
x=pos.curX;
y=pos.curY;
while(1)
{
point=0;
goxy(x,y);
GetString(str,4);
ReMoveSpece(str,subject);
stringlen=strlen(subject);
if (subject[0]==0) //判断是否空字符串
{
Blank();
continue;
}
for (i=0;i<stringlen;i++)
{
if (subject[i]=='.')
{
point++;
}
}
if (!isdigit(subject[0])&&!isdigit(subject[1])&&!isdigit(subject[2])&&!isdigit(subject[3])
&&(subject[0]!='.') &&(subject[1]!='.') &&(subject[2]!='.') &&(subject[3]!='.'))
{
goxy(2,20);
printf("The Grade is only inputed number,please input a result[0-100]:");
goxy(2,21);
printf("Please input any ch to continue");
getch();
goxy(x,y);
printf(" ");
goxy(2,20);
printf(" ");
goxy(2,21);
printf(" ");
continue;
}
if(point>1)
{goxy(2,20);
printf("You Only can input one point!!!");
goxy(2,21);
printf("Please input anych to continue");
getch();
goxy(x,y);
printf(" ");
goxy(2,20);
printf(" ");
goxy(2,21);
printf(" ");
continue;
}
result=(float)(atof(subject));
if (result<0||result>100||((int)(result*100)%100!=50 && (int)(result*100)%100!=0))
{
goxy(2,20);
if (result<0)
printf("The result is too small,please input a age between 0 to 100:");
else if(result>100)
printf("The result is too big,please input a age between 0 to 100");
else if(((int)(result*100)%100!=50 && (int)(result*100)%100!=0))
printf("Please input .0||.5");
goxy(2,21);
printf("Please input anych to continue");
getch();
goxy(x,y);
printf(" ");
goxy(2,20);
printf(" ");
goxy(2,21);
printf(" ");
continue;
}
goxy(x,y);
printf(" ");
goxy(x,y);
printf("%.1f",result);
break;
}
return result;
}
////////////////////////输入限定个数的字符////////////////////
int GetString(char str[],int lenmax)
{
int i=0;
while (1)
{
str[i]=getch();
if (str[i]=='\r') //判断回车
{
str[i]='\0';
return i;
}
if (str[i]=='\b') //退格
{
if (i==0)
{
continue;
}
else
{
printf("\b \b");
i--;
continue;
}
}
if (i==lenmax) //字数满了
{
continue;
}
if (str[i]==9||str[i]<=0) //如果是非打印字符和Tab
{
str[i]=getch();
continue;
}
else //如果为打印字符
{
putchar(str[i]);
i++;
continue;
}
}
}
int RestrictCode(char buffer[], int maxLen)
{
int pos=0;
int readch;
while((readch=getch())!='\r' )
{
if (readch=='\b')
{
if(pos>0)
{
pos--;
printf("\b \b");
}
continue;
}
if(readch==224||readch==0)
{
_getch();
continue;
}
if(pos <maxLen)
{
putch(' ');
putch('\b');
putch(42);
}
else continue;
buffer[pos++]=readch;
}
printf("\r\n");
if(pos <maxLen)buffer[pos]=0;
return pos;
}
void LandToSystem()
{
char str[20],str1[20];
char d[21]={"0123456789"};
char e[7]={"012345"};
char c[15];
int j,n=0;
InterPhase();
WinMessage("LandSystem");
goxy(26,5);
printf("UserName is :");
goxy(26,8);
printf("UserCode is :");
for(j=2;j>=0;j--)
{
goxy(40,5);
printf(" ");
goxy(40,8);
printf(" ");
goxy(40,5);
GetString(str,15);
goxy(22,18);
printf(" ");
ReMoveSpece(str,str1);
if(!(strlen(str1)==10))
{
goxy(22,18);printf("you must input 10 dige char!! ");
j++;
continue;
}
goxy(22,18);
printf("Please input right code!!");
goxy(40,8);
RestrictCode(c,10);
printf(" ");
printf("\n");
if ((strcmp(str1,d)==0)&&(strcmp(c,e))==0)
{
goxy(22,18); printf("you are right!"); system("pause");
break;break;
}
else
{
if (j<=2&&j>0)
{
goxy(22,18);
printf(" ");
goxy(22,18);
printf("you input wrong,you only have %d chance",j);goxy(40,8);}
else
{
exit(0);
}
}
}
}
void ReMoveSpece(char str[],char str1[])
{
char *p,*p1;
p=str;p1=str1;
while(*p==' ') p++;
while(*p!='\0') *p1++=*p++;
p1--;
while(*p1==' ') p1--;
p1++;
*p1='\0';
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -