Write a C program that reads several different names and addresses into the computer, rearranges the names into alphabetical order, and then writes out the alphabetized list. Make use of structure variables within the program
#include<string.h>
#define MAX 20
struct alphabetic
{
char name[50];
char address[100];
}s[MAX], temp;
int main(void)
{
int i, j, index;
char t[100], min;
for(i=0; i<MAX; i++)
{
printf("\nEnter name: ");
scanf("%s", s[i].name);
printf("Enter address: ");
scanf("%s", s[i].address);
}
printf("/-----------------------------------------------------\n");
printf("Name\tAddress\n");
for(i=0; i<MAX; i++)
{
for(j=i+1; j<MAX; j++)
{
if(strcmp(s[j].name, s[i].name)<0)
{
temp = s[j];
s[j] = s[i];
s[i] = temp;
}
}
printf("%s\t%s\n", s[i].name, s[i].address);
}
printf("/------------------------------------------------------\n");
return 0;
}
#define MAX 20
struct alphabetic
{
char name[50];
char address[100];
}s[MAX], temp;
int main(void)
{
int i, j, index;
char t[100], min;
for(i=0; i<MAX; i++)
{
printf("\nEnter name: ");
scanf("%s", s[i].name);
printf("Enter address: ");
scanf("%s", s[i].address);
}
printf("/-----------------------------------------------------\n");
printf("Name\tAddress\n");
for(i=0; i<MAX; i++)
{
for(j=i+1; j<MAX; j++)
{
if(strcmp(s[j].name, s[i].name)<0)
{
temp = s[j];
s[j] = s[i];
s[i] = temp;
}
}
printf("%s\t%s\n", s[i].name, s[i].address);
}
printf("/------------------------------------------------------\n");
return 0;
}
excellent
ReplyDeletePlease //comment
ReplyDeleteIt does not arrange it alphabetically
ReplyDelete