C语言(英文版)(所有分就这么多了,那位大侠救救)

来源:百度知道 编辑:UC知道 时间:2024/06/11 05:29:23
Write a program that arranges a set of given words in alphabetical order. The words are given in a file called
input-words.txt. The output is written to file output-words.txt. Assume that the input and output files contains
one word per line.
Example input file contents:
january
February
march
April
Output file contents:
April
February
january
march
Note: The character comparison is case insensitive. Call this program word-order.c.

对给出的单词按字母表排序写一个程序,这些单词放在input-words.txt这个文件中。输入输出都是一个单词占用一行,举例如下
输入文件包括:
january
February
march
April
Output file contents:
April
February
january
march
注意:字符比较没有大小写之分,这个程序名字是word-order.c

#include <stdio.h>

struct wordlink {
char *word;
wordlink *next;
};

void main()
{
FILE *inFile, *outFile;

if ((inFile= fopen( "input-words.txt", "r" )) == NULL)
{
printf("input-words.txt don't exist!\n");
}
if ((outFile= fopen( "output-words.txt", "w+" )) == NULL)
{
printf("output-words.txt don't exist!\n");
}

if (inFile != NULL && outFile != NULL)
{
wordlink * head;
wordlink * p;
wordlink * last;
wordlink * curPos;
char buff[100];
int wordLen;

head = p = NULL;