c - Issue with array of pointers -


i'm writing program alphabetize inputted names , ages. ages inputted separately, know need use array of pointers tie ages array of names can't quite figure out how go doing it. ideas?

so far, program alphabetizes names.

/* program alphabetize list of inputted names , ages */  #include <stdio.h> #define maxpeople 50 #define strsize   int alpha_first(char *list[], int min_sub, int max_sub); void sort_str(char *list[], int n);  int main(void) {     char people[maxpeople][strsize];     char *alpha[maxpeople];     int num_people, i;     char one_char;      printf("enter number of people (0...%d)\n> ", maxpeople);     scanf("%d", &num_people);              scanf("%c", &one_char);     while (one_char != '\n');      printf("enter name %d (lastname, firstname): ", );     printf("enter age %d: ", );     (i = 0; < num_people; ++i)         gets(people[i]);      (i = 0; < num_people; ++i)         alpha[i] = people[i];     sort_str(alpha, num_people);      printf("\n\n%-30s5c%-30s\n\n", "original list", ' ', "alphabetized list");      (i = 0; < num_people; ++i)         printf("-30s%5c%-30s\n", people[i], ' ', alpha[i]);      return(0); }  int alpha_first(char *list[], int min_sub, int max_sub) {     int first, i;      first = min_sub;     (i = min_sub + 1; <= max_sub; ++i)         if (strcmp(list[i], list[first]) < 0)             first = i;      return (first); }  void sort_str(char *list[], int n) {     int fill, index_of_min;     char *temp;      (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;         }     } } 

most of printfs syntax errors, in

printf("enter name %d (lastname, firstname): ", ); printf("enter age %d: ", ); 

or bomb right away, since pass int (' ') pointer:

printf("\n\n%-30s5c%-30s\n\n", "original list", ' ', "alphabetized list"); 

as first step, all %s right , show really compiled, not random garbage. , crank compiler's warning level maximum, need it! is

#define strsize 

supposed mean when strsize used arary dimension? have serious cut&paste problem, appear.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -