Write c program to create array of student names and search given name is found or not.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,n,j,found=0; // n=no of student
char name[10][15]; // name=student name
char nm[15]; //nm= search student name
clrscr(); //To clear Screen
printf("\n Enter how many student name: ");
scanf("%d",&n);
//To accept student details
for(i=0;i<n;i++)
{
printf("\n Enter student name: ");
scanf("%s",&name[i]);
}
printf("\n Enter search student name: ");
scanf("%s",&nm);
for(j=0;j<n;j++)
{
if(strcmp(name[j],nm)==0) // The strcmp() function is used to compare two strings
{
found=1;
break;
}
}
if(found==1)
printf("%s is found.",nm);
else
printf("%s is not found.",nm);
getch();
}
0 Comments