Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

chazog / iax0583

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Members
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Commit 390eebdd authored 6 years ago by chazog's avatar chazog
Browse files
Options
  • Browse Files
  • Download
  • Email Patches
  • Plain Diff

Upload New File

parent 5651d8cd master
Show whitespace changes
Inline Side-by-side
Showing with 78 additions and 0 deletions
  • Lab5/Task4.c
Lab5/Task4.c 0 → 100644
View file @ 390eebdd
#include <stdio.h>
#include <string.h>
#define STRSIZ 30
#define MAXAPP 50
int alpha_first(char *list[], int min_sub, int max_sub);
void select_sort_str(char *list[], int n);
int main(void)
{
char applicants[MAXAPP][STRSIZ];
char *alpha[MAXAPP];
int num_app, i;
char one_char;
printf("Enter number of applicants (0 . . %d)\n> ", MAXAPP);
scanf("%d", &num_app);
do
scanf("%c", &one_char);
while (one_char != '\n');
printf("Enter names of applicants on separate lines\n");
printf("in the order in which they applied\n");
for (i = 0; i < num_app; ++i)
scanf("%s", applicants[i]);
for (i = 0; i < num_app; ++i)
alpha[i] = applicants[i];
select_sort_str(alpha, num_app);
printf("\n\n%-30s%5c%-30s\n\n", "Application Order", ' ', "Alphabetical Order");
for (i = 0; i < num_app; ++i)
printf("%-30s%5c%-30s\n", applicants[i], ' ', alpha[i]);
return (0);
}
int alpha_first(char *list[], int min_sub, int max_sub)
{
int first, i;
first = min_sub;
for (i = min_sub + 1; i <= max_sub; i++)
{
if (strcmp(list[i], list[first]) < 0)
{
first = i;
}
}
return (first);
}
void select_sort_str(char *list[], int n)
{
int fill, index_of_min;
char *temp;
for (fill = 0; fill < n - 1; fill++)
{
index_of_min = alpha_first(list, fill, n - 1);
if (index_of_min != fill)
{
temp = list[index_of_min];
list[index_of_min] = list[fill];
list[fill] = temp;
}
}
}
This diff is collapsed. Click to expand it.
  • Write
  • Preview
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment