#include "stdafx.h" #include <conio.h> #include <stdio.h> #include <string> #include <iostream> using namespace std; struct word { char value[25]; int number; }; int main() { char str[200], str1[200]; int m = 0, k = 0; FILE *file, *file1, *file2; if( ( file = fopen( "text.txt", "r" ) ) == NULL ) { puts( "Error" ); exit( 1 ); } while( fgets( str, 200, file ) == NULL ); fclose( file ); char *ptr = strtok( str, ",.-!?" ); while( ptr != NULL ) { cout << ptr; if( ( file1 = fopen( "new.txt", "a" ) ) == NULL ) { puts( "Error" ); exit( 1 ); } fputs( ptr, file1 ); fclose( file1 ); ptr = strtok( NULL, ",.-!?" ); } cout << endl; cout << "ZZZ" << endl; if( ( file2 = fopen( "new.txt", "r" ) ) == NULL ) { puts( "Error" ); exit( 1 ); } fgets( str1, 200, file2 ); for( int i = 0; i < 200; i++ ) { if( str1[i] == ' ' ) { k++; } } cout << "AAA" << endl; cout << "The number of the words = " << k + 1 << endl; fclose( file2 ); word *d = new word[k]; if( ( file2 = fopen( "new.txt", "r" ) ) == NULL ) { puts( "Error" ); exit( 1 ); } while( fscanf( file2, "%s", d[m].value ) != EOF ) { m++; } fclose( file2 ); for( int i = 0; i < k + 1; i++ ) { cout << d[i].value << endl; } cout << "ZZZ" << endl; for( int i = 0; i < k + 1; i++ ) { d[i].number = 1; } for( int i = 0; i < k + 1; i++ ) { for( int j = 0; j < k + 1; j++ ) { if( i != j ) { if( _stricmp( d[i].value, d[j].value ) == 0 ) { d[i].number++; } } } } for( int i = 0; i < k + 1; i++ ) { if( d[i].number ) { cout << "The number of word which are the same with " << d[i].value << " " << d[i].number << endl; } } _getch(); return 0; } This program counts the number of occurrences of each word in the text. At the end she displays the word and the amount. The problem is that each word is displayed, but it is true, but you need one instance to write to the new file and the word. I wanted to rewrite the word and its number of entries into the new structure one by one, but could not. Help.