#include #include int main() { //Declare all variables in the beginning. FILE* fin; FILE* fout; int count = 0; char curword[5]; fin = fopen("words.dat","r"); //open file with "read" mode fout = fopen("output.txt","w+t"); //open file with "write" mode //Exit if files are not opened successfully if(fin == NULL || fout == NULL) { fprintf(stdout,"Failed to open input file or output file.\n"); exit(-1); } //Read and write strings while(fscanf(fin,"%s", curword) != EOF && count < 300 ) { fprintf(fout,"%s\t", curword); count++; if(count%5 == 0) fprintf(fout,"\n"); } //write the total number of words (output integer) fprintf(fout,"\n\nTotal number of words: %d\n",count); fclose(fin); fclose(fout); return 0; }