Here is the entire code for refference. Also the contents of the Crypto.exe
Code:
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
#include <string.h>
int main()
{
/*? is this used? Delete it if not*/ int CurentFileLine=1;
char** Cryptolexo;
int numI=0, numJ=0, iWord=1, NWords=0;
int x=0, y=0;
char** FindedWordArray;
char *CurentWordArray;
char *mystring;
mystring=(char*) malloc (100* sizeof(int));
CurentWordArray=(char*) malloc (50* sizeof(int));
int CurentWordSize=0, NLettersFound=0;
//CurentWordArray=(char*) malloc (CurentWordSize* sizeof(int));
int Choice=0, i=0,j=0,Tempi=0,Tempj=0, Ianc=0,Janc=0; //Ianchor,Janchor
int SsameLetters=0;
FILE * pFile;
char *ptr = 0;
//Zeroing Array String
for (i=0; i<=100; i++ )
{
mystring[i]=0;
}
//Open File
pFile = fopen ("crypto.txt" , "r");
//Reading of Dimensions and creation of 2D dynamical Array
j=0; i=0;
while ( (fgets (mystring , 100 , pFile) != NULL) && i<1 )
{
numJ = atoi (mystring);
//printf("\n The Converted String %c in Number is : %d ",numJ, numJ);
Cryptolexo = (char **) malloc(numJ * sizeof(int *));
FindedWordArray = (char **) malloc(numJ * sizeof(int *));
numI = atoi (mystring);
for(x = 0; x < numJ; x++)
{
Cryptolexo[x] = (char *) malloc(numI * sizeof(int));
FindedWordArray[x] = (char *) malloc(numI * sizeof(int));
}
i++;
}
//Reading of Array as its red from the file
j=0; i=0;
while ( (fgets (mystring , 100 , pFile) != NULL) && i<numI )
{
for(j = 0; j < numJ; j++)
{
Cryptolexo[i][j] = mystring[j];
//printf("%c", Cryptolexo[i][j]);
}
//printf("\n");
i++;
}
//Shows the Array after it has red it
j=0; i=0;
for(i = 0; i < numI; i++)
{
for(j = 0; j < numJ; j++)
{
printf("%c", Cryptolexo[i][j]);
}
printf("\n");
}
//Read of Number of Words to be find into the cryptolex
NWords = atoi (mystring);
//Reading of Each Word and Search
//Test Read and search of 1 Word "AX" horizontaly in the middle of the array
printf("\n");
j=0; i=0;
while ( /*(fgets (mystring , 100 , pFile) != NULL) &&*/ iWord<=NWords )
{
printf("\n\n----------------------------------------\n");
//Obdainance (from the file) of the Specific word to be searched and search of it
//----------------------------------------------------------------
// 0 Zeroing
for (i=0; i<=100; i++ ){mystring[i]=0;}
// 0 Zeroing
i=0; while (i<=50 ){CurentWordArray[i]=0; i++; }
// 0 Zeroing
i=0; j=0; for(i = 0; i < numI; i++)
{ for(j = 0; j < numJ; j++){FindedWordArray[i][j]=0;} }
//----------------------------------------------------------------
//Read of Word and put letter by letter into the array
fgets (CurentWordArray , 50 , pFile);
puts(CurentWordArray);
//Finds number of letters of the specific word
i=0; CurentWordSize=0;
while (CurentWordArray[i]!=0 )
{
CurentWordSize++;
i++;
if (CurentWordArray[i]==0){CurentWordSize--;}
}
printf("The Size of this Seeking Word is: %d",CurentWordSize);
//
//ALGORITHM OF SEARCH
Ianc=0; Janc=0; j=0; SsameLetters=0;
while (Ianc<=numI)
{
Janc=0;
while (Janc<=numJ-CurentWordSize)
{
j=0;
while (j<=CurentWordSize-1)
{
//THESE ARE THE IFS TRY PUTING OUT
//OF COMMENTS EVEN THE i=65000; IT WILL CRASH
//At the first difference it "kils" the whiles and zeros the
//finded word array to search the next block of boxes
if (Cryptolexo[Ianc][Janc+j]!=CurentWordArray[j])
{
/*
j=65000;
// 0 Zeroing
Tempi=0; Tempj=0; for(Tempi = 0; Tempi < numI; Tempi++)
{for(Tempj = 0; Tempj < numJ; Tempj++){FindedWordArray[Tempi][Tempj]=0;} }
//------------------------------------------
*/
}
//if the same sums the same letters
if (Cryptolexo[Ianc][Janc+j]==CurentWordArray[j])
{/*
// printf("Equal");
//SsameLetters++;
//FindedWordArray[Ianc][Janc+j]=Cryptolexo[Ianc][Janc+j];
*/
}
j++;
}
Janc++;
if (SsameLetters==CurentWordSize)
{ Ianc=65000; Janc=65000; j=65000;
// ^^ Write the Finded word Array (cause it has to appera as found)
Tempi=0; Tempj=0; for(Tempi = 0; Tempi < numI; Tempi++)
{ for(Tempj = 0; Tempj < numJ; Tempj++){printf("%c", FindedWordArray[Tempi][Tempj]);}printf("\n"); }
//-----------------------------------------
}
}
Ianc++;
}
//END-ALGORITHM SEARCH
//*/
// printf("\n");
iWord++;
}
fclose (pFile);
//TEST OF A SIMILAR COMPARISON THAT WORKS WITH NO PROBLEM
i=0;j=1; Tempi=1;
CurentWordArray[1]='3';
Cryptolexo[1][1]='3';
printf("\n\nCurentWord Array[%d]: %c",i, CurentWordArray[i+Tempi]);
printf("\n\nCurentCryptolexo[%d]: %c",i, Cryptolexo[i+Tempi][1]);
if(CurentWordArray[i+Tempi]==Cryptolexo[i+Tempi][1]){ printf("\nEqual"); }
if(CurentWordArray[i+Tempi]!=Cryptolexo[i+Tempi][1]){ printf("\nUnEqual"); }
scanf("%d", &Choice);
for(j = 0; j < numJ; j++) {free(Cryptolexo[j]); free(FindedWordArray[j]); }
free(Cryptolexo);
free(FindedWordArray);
return 0;
}
THE CONTENTS OF THE Crypto.exe
The dimensions that the array will have
The array's contents
The number of letters contained
and the letters to be find
Code:
5
5
OREAO
LEGT
AIIE
AXM
NSKOE
9
AXM
OREA
EOK
OLA
META
EIMAI
OXI
NAI
OTI