#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[100], str1[100];
int i = 0, k = 0;
FILE* file, *file1, *file2;
if ((file = fopen("text.txt", "r")) == NULL)
{
puts("Error");
exit(1);
}
while (fgets(str, 100, 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, 100, file2);
for (int i = 0; i < 100; 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[i].value) != EOF)
{
i++;
}
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++)
{
for (int j = 1; j < k + 1; j++)
{
d[i].number = 1;
if (i != j) {
if (strcmp(d[i].value, d[j].value) == 0)
d[i].number++;
}
}
}
for (int i = 0; i < k + 1; i++)
cout << "The number of word which are the same with "<< d[i].value<< d[i].number << endl;
_getch();
return 0;
}
Не показывает количество каждого слова, выдает -8513...