Greetings fellow programmers. I'm just starting out as a programmer in Microsoft Visual C++ Express and i've run into a stump with a more or less simple program.
The aim is to open an input file, read the file and store it, then alphabetically sort and display them.
My programming is sound for the alphabetically sorting and displaying, but once I changed my code from manually inputing the names to trying to read them from an input file, things went horribly wrong. Here is my code so far: any help would be greatly appreciated.
Code:
Code:
#include
"stdafx.h"
#include
"string.h"
#define
STRSIZE 21
#define
MAXBAT 16
int
alpha_first(char *list[], int min_sub, int max_sub);
void
select_sort_str(char *list[], int n);
int
main(void)
{
char batters[MAXBAT][STRSIZE];
char batman[STRSIZE];
char *alpha[MAXBAT];
int num_bat = 0;
int i = 0;
FILE *inpa;
int inpa_status;
inpa = fopen("H:\\GENG1003\\input2a.dat", "r");
inpa_status = fscanf(inpa, "%s", &batman);
num_bat = 16;
while (inpa_status != EOF){
printf("\nPlayer:\n%s\n", batman);
inpa_status = fscanf (inpa, "%s", &batman);
strcpy(batman[STRSIZE],batters[MAXBAT]);
}
for (i = 0; i < num_bat; ++i){
alpha[i] = batters[i];
}
select_sort_str(alpha, num_bat);
printf("\n\n%-30s%5c%-30s\n\n", "Application Order", ' ', "Alphabetical Order");
for (i = 0; i < num_bat; ++i){
printf("%-30s%5c%-30s\n", batters[i], ' ', alpha[i]);
}
fclose(inpa);
return 0;
}