Query of employee information mini project in C

This project program is to take employee details from the user and it prints the required details of that specific employee based on what the user has searched. Suppose the user wants to know about all the employee details of the employees who have a salary of 20,000. By clicking on ‘s’ and typing in the salary amount (here 20,000) the user can get all the details about that employee. This program uses Structures, Functions, switch and pointers.

It initially takes the input from the user, displays it once and then it calls the ransom function(I was listening to that song so i just named it ransom), asks the user what to search for and uses switch case and calls another function which checks the condition and prints the required output.

//EMPLOYEE STRUCTURE
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct employee
{
    char name[50];
    int id;
    char dep[50];
    float sal;
};
void ransom(struct employee *ptr, int n);
void search(struct employee *ptr, int n,char opt);
void searchnum(struct employee *ptr, int n,float num,char opt);
void main(){
    struct employee *ptr;//gives a pointer value to emp
    int i,n;
    printf("Enter no of employee\n");
    scanf("%d",&n);
    ptr=(struct employee*)malloc(n*sizeof(struct employee));
    printf("Enter details of employee %d",n);
    for(i=0;i<n;i++){
        printf("\nEnter the %d name:",i+1);
        scanf("%s",&(ptr+i)->name);//-> moves taken input into the said pointer
        printf("\nEnter the %d id:",i+1);
        scanf("%d",&(ptr+i)->id);
        printf("\nEnter the %d dept:",i+1);
        scanf("%s",&(ptr+i)->dep);
        printf("\nEnter the %d salary:",i+1);
        scanf("%f",&(ptr+i)->sal);
    }
    printf("Employee details are :\n");
    for(i=0;i<n;i++){
        printf("Employee %d details\n",i+1);
        printf("Employee %d name: %s \n",i+1,(ptr+i)->name);
        printf("Employee %d id: %d \n",i+1,(ptr+i)->id);
        printf("Employee %d department: %s \n",i+1,(ptr+i)->dep);
        printf("Employee %d salary: %f \n",i+1,(ptr+i)->sal);
    }
    ransom(ptr,n);
}

void search(struct employee *ptr,int n,char opt){
            char ename[50];
             printf("\nEnter search element:");
            scanf("%s",ename);
    if(opt=='n'){
        //opt='name';

        for(int i=0;i<n;i++){//linear search
        printf("%s",ptr[i].name);
        if(strcmp(ptr[i].name,ename)==0){
            printf("bug");            
            printf("\nEntire details of %c",opt);
            printf("Employee %d name: %s \n",i+1,(ptr+i)->name);
            printf("Employee %d id: %d \n",i+1,(ptr+i)->id);
            printf("Employee %d department: %s \n",i+1,(ptr+i)->dep);
            printf("Employee %d salary: %f \n",i+1,(ptr+i)->sal);
        }
    }
    }
    else if (opt=='d'){
        //opt='dep';
        for(int i=0;i<n;i++){
        if(strcmp(ptr[i].name,ename)==0){
            printf("\nEntire details of %c",opt);
            printf("Employee %d name: %s \n",i+1,(ptr+i)->name);
            printf("Employee %d id: %d \n",i+1,(ptr+i)->id);
            printf("Employee %d department: %s \n",i+1,(ptr+i)->dep);
            printf("Employee %d salary: %f \n",i+1,(ptr+i)->sal);
        }
    }
    }
    else{
        printf("\nNot present\n");
    }
}
void searchnum(struct employee *ptr, int n,float num,char opt){
    if(opt=='s'){
        for(int i=0;i<n;i++){
            if(num==ptr[i].sal){
            printf("\nEntire details of %d\n",num+1);
            printf("Employee %d name: %s \n",i+1,ptr[i].name);
            printf("Employee %d id: %d \n",i+1,(ptr+i)->id);
            printf("Employee %d department: %s \n",i+1,ptr[i].dep);
            printf("Employee %d salary: %f \n",i+1,(ptr+i)->sal);
            }
        }
    }
    else if(opt=='i'){
        for(int i=0;i<n;i++){
            if((int)num==ptr[i].id){
            printf("\nEntire details of %d\n",num+1);
            printf("Employee %d name: %s\n",i+1,(ptr+i)->name);
            printf("Employee %d id: %d\n",i+1,(ptr+i)->id);
            printf("Employee %d department: %s\n",i+1,(ptr+i)->dep);
            printf("Employee %d salary: %f\n",i+1,(ptr+i)->sal);
            }
        }
    }
    else{
        printf("\n not present \n");
    }
}
void ransom(struct employee *ptr,int n)
{
    int i;
    while(1){
    char opt;
    int num;
    printf("Enter either name (n), id(i), department(d) or salary(s) to list out employees and exit(o) to exit\n");
    scanf(" %c",&opt);

    switch(opt){
        case 'n':

        search(ptr,n,opt);
        break;
        case 'i':printf("\nEnter id:");
        scanf("%d",&num);
        searchnum(ptr,n,num,opt);
        break;
        case 'd':
        search(ptr,n,opt);
        break;
        case 's':
        printf("\nEnter salary:");
        scanf("%d",&num);
        searchnum(ptr,n,num,opt);
        break;
        case 'o':exit(0);
        break;
        default:printf("Wront input man\n");
    }
}
}

If you have any doubt about the code or suggest any improvement just comment.

Happy coding…