/* * main.c - call sortfile() (any version of sortfile()) on two files, with * file names input by the user. * * Alan J Rosenthal, November 2000. */ #include #include int main() { char filename[100]; FILE *in, *out; extern void sortfile(FILE *in, FILE *out); extern void myget(char *prompt, char *s, int size); /* get filenames and open files */ myget("Input file: ", filename, sizeof filename); if ((in = fopen(filename, "r")) == NULL) { perror(filename); return 1; } myget("Output file: ", filename, sizeof filename); if ((out = fopen(filename, "w")) == NULL) { perror(filename); return 1; } /* call sortfile on 'em; files closed upon program exit */ sortfile(in, out); return 0; } void myget(char *prompt, char *s, int size) { char *p; printf("%s", prompt); if (fgets(s, size, stdin) == NULL) exit(0); if ((p = strchr(s, '\n')) != NULL) *p = '\0'; }