Write a c program to crate a student structure having field stud_name and address accept the details of ‘n’ student into the structure, rearrange the data in alphabetic order of stud_name and display the result

#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<stdlib.h>
#include<process.h>
struct stud
{
char name[50];
char add[50];
}s[100],t[100];
void main()
{
int i=0,j=0,n;
clrscr();
printf("\n enter the limit ");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\n enter the name and add");
printf("\n enter the name= ");
scanf("%s",s[i].name);
printf("\n enter the address= ");
scanf("%s",s[i].add);
}
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(strcmp(s[i].name,s[j].name)>0)
{
strcpy(t,s[i].name);
strcpy(s[i].name,s[j].name);
strcpy(s[j].name,t);
}
}
}
for(i=0;i<n;i++)
{
printf("\n name =%s",s[i].name);
printf("\n address=%s",s[i].add);
}
getch();
}

No comments:

Post a Comment