2011, the first test of the operation of the document, after 2016 years also examined the operation of the file
Title: Read a file, sort the read string by character size, and output to another file
/*
read a file, sorted by character size of the read string, output to another file/
*
#include <stdio.h>
#include <stdlib.h>
int cmp (const void *a, const void *b) {return
* (char *) A-* (char *) b;
}
int main ()
{
FILE *in, *out;
Char infilename[20] = "In.txt";
Char outfilename[20] = "OUT.txt";
if (in = fopen (Infilename, "r") = = NULL) {
printf ("Cannot open%s\n", infilename);
Exit (0);
}
if (out = fopen (Outfilename, "w+"))!= NULL) {
// printf ("Cannot open%s\n", outfilename); exit (0);
}
Char str[80];
int length=0;
while (!feof (in)) {
fscanf (in, "%s", str);
fprintf (out, "%s", str);
}
while (str[length++] "!=");
length = length-1;
Qsort (str, length, sizeof (str[0]), CMP);
printf ("%s", str); fclose (in); fclose (out);
}