Skip to main content

College Management System

 

 
# include <stdio.h>
# include <conio.h>
# include <string.h>                      

struct student{
        long roll ;
        char name[20];
        char branch[20];
};


int add()
{
struct student s;
system("cls");
    FILE *fp;
    char c;
    fp=fopen("record.txt","a");
    while (1)
    {
      
      printf("ENTER THE Roll Number:->");
      scanf("%ld",&s.roll);
      fflush(stdin);
      printf("\nENTER THE NAME               :->");
      scanf("%s",s.name);
      fflush(stdin);
      printf("\nENTER THE BRANCH            :->");
      scanf("%s",s.branch);
      fwrite(&s,sizeof(s),1,fp);
      fflush(stdin);
      printf("\n\nWISH TO CONTINUE?(Y/N)");
      scanf("%c",&c);
      if(c=='n' || c=='N')
            break;
           
    }
    system("cls"); 
    fclose(fp);
    return 0;
}

int search()
{
struct student s;
system("cls"); 
    FILE *fp;
    char sname[20];
fp=fopen("record.txt","r");
                    
    printf("ENTER THE NAME    :->");
    scanf("%s",sname);
    while(fread(&s,sizeof(s),1,fp))
    {
        if(strcmp(sname,s.name)==0)
        {
            printf("\n\t%ld\t %s\t %s",s.roll,s.name,s.branch);
            getch();
            break;
        }
    }
    system("cls"); 
    fclose(fp);
    return 0;
    getch();
}

void delete()
{
     struct student s;
     system("cls"); 
FILE *fp;
FILE *ft;
int r, t;
printf("Enter the Roll no you want to delete :");
scanf("%d", &r);
if (r == 0)
  printf("Roll no %d is not available in the file\n", r);
else
{
  fp = fopen("record.txt", "r");
  ft = fopen("temp.txt", "w");
  while (fread(&s, sizeof(s), 1, fp))
  {
   t = s.roll;
   if (t != r)
    fwrite(&s, sizeof(s), 1, ft);
  }
  fclose(fp);
  fclose(ft);
  fp = fopen("record.txt", "w");
  ft = fopen("temp.txt", "r");
  while (fread(&s, sizeof(s), 1, ft))
   fwrite(&s, sizeof(s), 1, fp);
  printf("\nRECORD DELETED\n");
  system("cls"); 
  fclose(fp);
  fclose(ft);
}
}
int display()
{
system("CLS");
struct student s;
    FILE *fp;
fp=fopen("record.txt","r");
while(fread(&s,sizeof(s),1,fp)==1)
{
printf("\n\t%ld\t %s\t %s",s.roll,s.name,s.branch);
           
            
}
system("cls"); 
fclose(fp);
getch();
return 0;
}

int update()
{
struct student s;
system("cls");
int avl;
FILE *ft;
FILE *fp;
int t, r, ch;
printf("Enter roll number to update:");
scanf("%d", &r);
avl = r;
if (avl == 0)
{
  printf("Roll number %d is not Available in the file", r);
}
else
{
  fp = fopen("record.txt", "r");
  ft = fopen("temp.txt", "w");
  while (fread(&s, sizeof(s), 1, fp))
  {
   t = s.roll;
   if (t != r)
    fwrite(&s, sizeof(s), 1, ft);
   else
   {
    printf("\n\t1. Update Name of Roll Number %d", r);
    printf("\n\t2. Update branch of Roll Number %d", r);
    printf("\n\t3. Update both Name and branch of Roll Number %d", r);
    printf("\nEnter your choice:");
    scanf("%d", &ch);
    switch (ch)
    {
    case 1:
     printf("Enter Name:");
     scanf("%s", &s.name);
     break;
    case 2:
     printf("Enter branch : ");
     scanf("%s", &s.branch);
     break;
    case 3:
     printf("Enter Name: ");
     scanf("%s", &s.name);
     printf("Enter Branch: ");
     scanf("%s", &s.branch);
     break;
    default:
     printf("Invalid Selection");
     break;
    }
    fwrite(&s, sizeof(s), 1, ft);
   }
  }
  fclose(fp);
  fclose(ft);
  fp = fopen("record.txt", "w");
  ft = fopen("temp.txt", "r");
  while (fread(&s, sizeof(s), 1, ft))
  {
   fwrite(&s, sizeof(s), 1, fp);
  }
  system("cls"); 
  fclose(fp);
  fclose(ft);
  printf("RECORD UPDATED");
 }
}
main()
{
    struct student s;
    FILE *fp;
    long rno;
    system("cls");
    int ch;
    while(1)
    {
   
        printf("\n\t\t**********************************************");
printf("\n\t\t*          College REGISTRATION SYSTEM      *");
printf("\n\t\t**********************************************");
printf("\n");
printf("\n\t\t\t[1]Add New Student Record  ");
printf("\n\t\t\t[2]Delete Student Record   ");
printf("\n\t\t\t[3]Display Student Record  ");
printf("\n\t\t\t[4]Modify Student Record   ");
printf("\n\t\t\t[5]Search Student Record   ");
printf("\n\t\t\t[6]Exit              ");
printf("\n\n\t\t\tPlease Enter Your Choice: ");
fflush(stdin);
        scanf("%d",&ch);
        switch(ch)
        {
            case 1:
                    add();
                    break;
            case 2:
                    delete();
                    break;        
            case 3:
                    display();
                    break;
case 4:
                    update();
                    break;         
            case 5:
                    search();
                    break;
            default : printf("Wrong!");
        }
    }
    getch();

}




Comments