does anyone tell me what's wrong with the program?
Code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<ctype.h>
#include<string.h>
struct llist
{
char word[20];
struct llist *next;
};
typedef struct llist node;
typedef node *llink;
llink insertnode(llink head,llink ptr,char str[20])
{
llink newnode;
newnode = (llink)malloc(sizeof(node));
if(!newnode)
return NULL;
newnode->word=str;
newnode->next=NULL;
newnode->next=ptr->next;
ptr->next=newnode;
return head;
}
llink deletenode(llink head,llink ptr)
{
llink previous;
previous=head;
while(previous->next!=ptr)
previous=previous->next;
previous->next=ptr->next;
free(ptr);
return head;
}
llink findnode(llink head,char str[20])
{
llink ptr;
ptr=head;
do
{
if (ptr->word==str)
return ptr;
ptr->next;
}while (head!=ptr && head!=head->next);
return NULL;
}
int main(void)
{
FILE *infile = fopen("wap.txt","r");
FILE *outfile = fopen("wordlist.txt","w");
FILE *infile1 = fopen("wordlist.txt","r");
FILE *outfile1 = fopen("wordlist1.txt","w");
llink head;
llink ptr;
int i=0,count=0;
if ( infile != NULL && outfile != NULL )
{
int terminate = 0;
for ( ;; )
{
int ch = fgetc(infile);
if ( ch == EOF )
{
break;
}
if ( isalpha(ch) )
{
fputc(ch, outfile);
terminate = 1; /* okay to add newline on next space */
}
else if ( isspace(ch) && terminate )
{
fputc('\n', outfile);
terminate = 0;
}
}
fclose(infile);
fclose(outfile);
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);
}
return 0;
}