#include <iostream>
int main ()
{
FILE* fp;
FILE* fo;
char* filename = "words.txt";
char* fileo = "output.txt";
char* pch;
char test[500];
fp = fopen(filename,"r");
if (!(fp = fopen(filename,"r"))) {
printf("\nCannot open %s for output.\n",filename);
return 1;
}
while (!feof(fp)) {
char* str=fgets (test , 500 , fp);
pch = strtok (str," ,.-\t");
}
fclose(fp);
fo = fopen(fileo,"w");
if (!(fo = fopen(fileo,"w"))) {
printf("\nCannot open %s for output.\n",fileo);
return 1;}
fo = fopen(fileo,"w");
fputs(pch,fo);
fclose(fo);
return 0;
}
input file :
test the ,whatever.this program
output file:
test
i want all the words to be there ,it only gives out the first one ,i think its cuz it thinks the file has ended so closes it and doesn't read anymore ,but i can't think how to fix this .,can someone help me out ?
next step is i want to do it on more than just one line .