Skip to content

Instantly share code, notes, and snippets.

@NightBrownie
Created May 5, 2011 19:00
Show Gist options
  • Save NightBrownie/957660 to your computer and use it in GitHub Desktop.
Save NightBrownie/957660 to your computer and use it in GitHub Desktop.
// Programming_4_2_lab_var_9.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <malloc.h>
#define NOS 32
/*char *(MotsList[50]);
int *(NumbOfSimbols[32]);
*/
typedef int Row[NOS];
typedef char Mot[50];
Row *NumbOfSimbols;
Mot *MotsList;
int ToUpRegister(int c);
int ToMotsList(char *FileName);
void FindMots(int);
void _tmain(int argc, _TCHAR* argv[])
{
char DicFileName[100];
printf("Please enter the dictionary file name:\n");
scanf("%s",DicFileName);
FindMots(ToMotsList(DicFileName));
puts("Please enter any key to close program...");
getch();
}
void FindMots(int NumberOfMots)
{
for (int i = 0; i < (NumberOfMots - 1); i++)
for (int j = i + 1; j < NumberOfMots; j++)
{
bool Buff = true;
for (int k = 0; k < NOS; k++)
if (NumbOfSimbols[i][k] != NumbOfSimbols[j][k])
{
Buff = false;
break;
}
if (Buff)
printf("Mot 1: %s\t Mot 2: %s",MotsList[i],MotsList[j]);
}
}
int ToMotsList(char *FileName)
{
FILE *fp;
char c = 0;
int j = 0, m = 0, n = 0;
fp = fopen("dictionary.txt"/*FileName*/,"r");
if (!fp)
{
perror("Opening file");
getch();
exit(1);
}
NumbOfSimbols = (Row*) malloc(0);
MotsList = (Mot*) malloc(50*sizeof(char));
while ((c = fgetc(fp)) != EOF)
{
if ((ToUpRegister(c) >= 128) && (ToUpRegister(c) <= 159))
{
int i = 0;
realloc(NumbOfSimbols, (n += NOS*sizeof(int)));
for (int i = 0; i < NOS; i++)
NumbOfSimbols[j][i] = 0;
realloc(MotsList, (m += NOS*sizeof(char)));
do
{
printf("%c",c);
int BufferValue = ToUpRegister(c);
MotsList[j][i] = BufferValue;
NumbOfSimbols[j][BufferValue - 'А' -1] += 1;
i++;
c = fgetc(fp);
}while ((ToUpRegister(c) >= 128) && (ToUpRegister(c) <= 159));
j++;
}
}
fclose(fp);
return j;
}
int ToUpRegister(int c)
{
c += 256;
if ((c >= 160) && (c <= 175))
{
return (c - 32);
}
else
{
if ((c >= 224) && (c <= 239))
{
return (c - 80);
}
else
{
return c;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment