i have no idea to delete the repeated word and sort the string. Can anyone help me?
i get the word from infile and generate the outfile which delete the repeated word.
for example
infile
i
am
i
a
boy
outfile
a
am
boy
i
my code is below. what's wrong? Thx everyone helps me
Code:
#include<stdio.h>
#include<stdlib.h>
struct llist
{
char word[20];
struct llist *next;
};
typedef struct llist node;
typedef node *llink;
void main()
{
FILE *infile1 = fopen("wordlist.txt","r");
FILE *outfile1 = fopen("wordlist1.txt","w");
llink head;
llink ptr;
int i=0,count=0;
head = ( llink ) malloc(sizeof(node));
head->next = NULL;
ptr = head;
while(!feof(infile1))
{
fscanf(infile1,"%s",ptr->word);
ptr->next = ( llink ) malloc(sizeof(node));
ptr->next->next = NULL;
ptr = ptr->next;
count++;
}
ptr = head;
while(i<count-1)
{
fprintf(outfile1,"%s\n",ptr->word);
ptr = ptr->next;
i++;
}
fclose(infile1);
fclose(outfile1);
}