I am a AD students. I have a question here. does anyone help me?
i am writing a program to get word from text file, which is an eassy. i need to sperate each word and then write to another text file. in the new text file, the word should be one word per line , no numbers or other char such as !, ? and many others, no double or something like that are allow.
i have wrote it, but something is wrong. I get word from text and write to the new text file but in the new text file. i have find the double line. Why does it cause? What's wrong is that?
for examples
in the text file
***************
i am a boy. i am 15 years old.
**************
in the new text file
i
am
a
boy
i
am
years
old
my code is here
Code:
#include<stdio.h>
void main()
{
FILE *fp,*fp1;
char word[1000000];
int i=0;
fp=fopen("wap.txt","r");
fp1=fopen("wordlist.txt","w");
while (!feof(fp))
{
fscanf(fp,"%c",&word[i]);
if(word[i] == ' ' || word[i]=='\n')
{
fprintf(fp1,"%c\n",word[i]);
}
else if (((word[i]>='a') && (word[i]<='z')) || ((word[i]>='A') && (word[i]<='Z')))
{
fprintf(fp1,"%c",word[i]);
}
}
fclose(fp);
fclose(fp1);
}