Main 1
Main 1
Main 1
h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <ctype.h>
#include <windows.h>
COORD coord={0,0};
char temp[120]="";
char temp2[20]="";
typedef struct
{
char name[SON],email[SOE],ph[10],adr[10],id[9];
} STU;
int main()
{
while (1)
choices();
getc(stdin);
return 0;
}
int add_student ()
{
STU stu;
FILE *add,*idstu;
int check;
char save,cont;
int len;
while(1)
{
save='n';
system("cls");
printf("enter the ID number of student :");
fflush(stdin);
gets(stu.id);
check=idcheck (stu.id);
if (check)
{
printf("the student is exit :\n");
searchstu(stu.id );
}
else
{
printf("enter the name of student :");
gets(stu.name);
len=strlen(stu.name);
stu.name[len]='\0';
printf("enter the address of student :");
gets(stu.adr);
printf("enter the phone of student :");
gets(stu.ph);
printf("enter the email of student :");
gets(stu.email);
len=strlen(stu.email);
stu.email[len]='\0';
if (save=='s')
{
idstu=fopen("id_number.txt","r+");
if (idstu == NULL)
idstu=fopen("id_number.txt","w");
add=fopen("data_of_student.txt","r+");
if (add == NULL)
add=fopen("data_of_student.txt","w");
fseek(idstu,-3,SEEK_END);
fseek(add,-3,SEEK_END);
fprintf(idstu,"%s\t",stu.id);
fprintf(add,"%s\t%s.\t%s\t%s\t%s\n\n",stu.id,stu.name,stu.adr,stu.ph,stu.
email);
fprintf(idstu ,"%s","eof");
fprintf(add ,"%s","eof");
fclose(idstu);
fclose(add);
}
// fprintf(idstu ,"%s","eof");
// fprintf(add ,"%s","eof");
//
// fclose(idstu);
// fclose(add);
return 0 ;
}
fclose(searchstud);
getc(stdin);
getc(stdin);
return 1;
}
int idsearch ()
{
system ("cls");
printf("enter the id number to search :");
scanf("%s",temp2);
searchstu(temp2);
int print()
{
system("cls");
int choice;
gotoxy(29,7);
printf("[1] add student .");
gotoxy(29,8);
printf("[2] search of student .");
gotoxy(29,9);
printf("[3] add marks .");
gotoxy(29,10);
printf("[4] Exit .");
gotoxy(29,20);
printf("enter number between 1 and 4 :");
gotoxy(29,21);
printf("enter your choice : ");
scanf("%d",&choice);
return choice;
}
int choices ()
{
int choice;
choice=print();
if (choice == 1) add_student();
else if (choice == 2)idsearch ();
else if (choice == 3)addmarks();
else if (choice == 4) exit(1);
else print();
int subjects ()
{
int sub;
system("cls");
gotoxy(29,7);
printf("[1] Mathematics :");
gotoxy(29,8);
printf("[2] C language :");
gotoxy(29,9);
printf("[3] Fluid mechanics :");
gotoxy(29,10);
printf("[4] Electronics :");
gotoxy(29,11);
printf("[5] Electric circuit :");
gotoxy(29,14);
printf ("enter number between 1 and 5");
gotoxy(29,15);
printf("choose the subject : ");
scanf("%d",&sub);
if(sub>5)
subjects();
if (sub<0)
subjects();
return sub;
}
int addmarks ()
{
int sub;
sub=subjects();
char check[10];
system("cls");
FILE *markf,*idm;
char idmark[10];
float mark;
if(sub==1)
{
markf=fopen("mathematics.txt","r+");
if (markf == NULL)
markf=fopen("mathematics.txt","w");
}
else if(sub==2)
{
markf=fopen("c_language.txt","r+");
if (markf == NULL)
markf=fopen("c_language.txt","w");
}
else if(sub==3)
{
markf=fopen("fluid mechanics.txt","r+");
if (markf == NULL)
markf=fopen("fluid mechanics.txt","w");
}
else if(sub==4)
{
markf=fopen("electronics.txt","r+");
if (markf == NULL)
markf=fopen("electronics.txt","w");
}
else if(sub==5)
{
markf=fopen("electric_circuit.txt","r+");
if (markf == NULL)
markf=fopen("electric_circuit.txt","w");
}
fseek(markf,-3,SEEK_END);
fscanf(markf,"%s",check);
if (strcmp(check,"eof"))
{
idm=fopen("id_number.txt","r");
while (1)
{
fscanf(idm,"%s",idmark);
if (!strcmp(idmark,"eof"))
{
fclose(idm);
fprintf(markf,"%s","eof");
fclose(markf);
return 1;
}
printf("enter the mark of student has ID number (%s) :",idmark);
scanf("%f",&mark);
fprintf(markf,"%s\t%f\t\n",idmark,mark);
}
}
else
{
printf("the marks is exist .");
getc(stdin);
getc(stdin);
}
fseek(markf,0,SEEK_END);
int n=ftell(markf);
fclose(markf);
}