Skip to main content

Featured

C Pattern Programs: Square Number and Alphabet Patterns Explained

๐Ÿ”ท Square Star Pattern ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = 1; i <= num; i++) { for(int j = 1; j <= num; j++) { printf("* ");//keep"* " } printf("\n"); } return 0; } ๐Ÿ”ท Reverse Square Alphabet Pattern (Column-wise) ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; printf("Enter the number:\n"); scanf("%d", &num); for(int i = num; i >= 1; i--) { for(int j = num; j >= 1; j--) { printf("%c ", j + 64);//%c for Character and 64 will be ASIIC VALUE } printf("\n"); } return 0; } ๐Ÿ”ท Reverse Square Alphabet Pattern (Row-wise) ๐Ÿ“‹ Copy Code #include <stdio.h> int main() { int num; ...

write a program Address Book in c

Address Book


-------------------------------------------------------------------------------------------------------------------

#include<stdio.h>

#include<string.h>

struct adressbook

{

    char name[30];

    char mob[15];

    char email[20];

    char adress[30];

};

void add_details(struct adressbook *,int *);

void edit_details(struct adressbook *,int *);

void search_details(struct adressbook *,int *);

void print_details(struct adressbook *,int *);

int main()

{

    struct adressbook user[30];

    int user_count=0,choice;

    int repeat=1;

    while(repeat)

    {


        printf("1. Add Details\n");

        printf("2. Edit Details\n");

        printf("3. search Details\n");

        printf("4. print Details\n");

        printf("Enter the choice:");

        scanf("%d",&choice);

        switch(choice)

        {

            case 1: add_details(user, &user_count);

                    break;

            case 2: edit_details(user, &user_count);

                    break;

            case 3: search_details(user, &user_count);

                    break;

            case 4: print_details(user,&user_count);

                    break;

            default:

                    printf("Invalid choice!!\n");

        }

        char ch;

        printf("Do you want to continue(y/n):");

        scanf(" %c",&ch);

        ch=='y' || ch=='Y'? (repeat=1):(repeat=0);

    }

    return 0;

}

void add_details(struct adressbook user[],int *user_count)

{

     int i=*user_count;

     printf("Enter Name: \n");

     scanf(" %[^\n]",user[i].name);

     printf("Enter Mobile Number: \n");

     scanf(" %[^\n]",user[i].mob);

     printf("Enter Email: \n");

     scanf(" %[^\n]",user[i].email);

     printf("Enter Adress: \n");

     scanf(" %[^\n]",user[i].adress);

     (*user_count)++;

     printf("Details are Added Successfully!!\n");

}

void print_details(struct adressbook user[],int *user_count)

{

    for(int i=0;i<*user_count;i++)

    {

        printf("%s, %s, %s, %s\n",user[i].name,user[i].mob,user[i].email,user[i].adress);

    }

}

void search_details(struct adressbook user[], int *user_count)

{

    char name[30];

    int found = 0;

    printf("Enter the Name of the contact you want to search: \n");

    scanf(" %[^\n]", name);

    for (int i=0;i<*user_count;i++)

    {

        if(strcmp(user[i].name, name)==0)

        {

            found=1;

            printf("%s, %s, %s, %s\n",user[i].name,user[i].mob,user[i].email,user[i].adress);

            break;

        }

    }

    if(found==0)

    {


        printf("Not Found in the list\n");

    }

}

void edit_details(struct adressbook user[], int *user_count)

{

    int choice;

    int i=*user_count;

    char edit[30];

    int found=0,record=0;

    printf("Enter The Name You Want To Edit:\n");

    scanf(" %[^\n]",edit);

    for (int i=0;i<*user_count;i++)

    if(strcmp(user[i].name,edit)==0)

    {

        record=i;

        found=1;

        break;

    }

    if(found==0)

    {


        printf("not found");

        return;

    }


        printf("1. Edit Name\n");

        printf("2. Edit Mobile Number\n");

        printf("3. Edit Email\n");

        printf("4. Edit Details\n");

        printf("Enter the choice:\n");

        scanf(" %d",&choice);

        switch(choice)

        {

        case 1:printf("enter the detail(name)\n");

               scanf("  %[^\n]",user[record].name);

               break;

        case 2:printf("enter the detail(mob)\n");

               scanf("  %[^\n]",user[record].mob);

               break;

        case 3:printf("enter the detail(email)\n");

               scanf("  %[^\n]",user[record].email);

               break;

        case 4:printf("enter the detail(address)\n");

               scanf("  %[^\n]",user[record].adress);

               break;

        default:

                printf("Invalid input!!");

        }


}

----------------------------------------------------------------------------------------------------------------------------

 

Comments

Popular Posts

๐ŸŒ™