*You store name of your friends in string array. You are given task to print name of your friend whose name start with particular character and after you find first name in the list you have stop searching and print name you search in the list

 /*You store name of your friends in string array. You are given task to print name of your friend whose name start with particular character and after you find first name in the list you have stop searching and print name you search in the list.*/


#include<stdio.h>


void main()

    char names[10][25]={ 

             "Ayush Gupta",

             "Shivang Shukla", 

             "Prakhar Mishra", 

             "Pratik Kumar", 

             "Priyansh Kumar Singh", 

             "Rudra Pratap", 

             "Sonal Kumari", 

             "Jatin", 

             "Akash Anand", 

             "Sneha Panwar"

    };

    char ch, friend[25];

    int flag=0;

    a:

    printf("Enter Character\n");

    scanf("%c", &ch);

    printf("Choose names of your friend starting with %c to print\n", ch);

    for(int i=0;i<10;i++)

    { 

        if(ch==names[i][0])

          {printf("%s\n", names[i]);

          flag++;}

    }

    if(flag==0)

    {printf("NO names Found With %c \n Again ", ch);

      goto a;

    }

    

    printf("Enter the name of your friend from the list above to print it \n");

    scanf("%s", &friend);

  

    for(int i=0;i<10;i++)

    { 

        if(strcmp(friend, names[i])==-1)

        printf("%s", names[i]);

    }

}

Comments