d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > C++ Find A Word In A Txt File
Add Reply New Topic New Poll
Member
Posts: 27,086
Joined: Mar 7 2008
Gold: 685.00
Oct 8 2013 10:16pm
I don't know what is wrong with this.

For example, I got "Hello World" in .txt file. I type "Hello" in the edit control then click the button. I got something wrong in the comment bellow. I compare this in the code:

Tab[0] // "Hello"
with
WordToFind // "Hello"
and condition is false... I don't get it




here is the code :

Code


HANDLE h;
HWND Liste;
char C;
char Val2 [250] = {0};
DWORD NbCarac =1;
int i = 0, j = 0;
char Val [30];
char Tab [25] [12] = {0};
char Trouve [10];
char WordToFind [15];
bool WordFound = false;

GetDlgItemText(hDlg, IDC_FILE, Val, 30);
GetDlgItemText(hDlg, IDC_WORD, WordToFind, 15);
h = CreateFile(Val, GENERIC_ALL, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
Liste = GetDlgItem(hDlg, IDC_Liste);

while (NbCaracLu != NULL)
{
if (!ReadFile(h, &C, 1, &NbCarac, NULL))
{
int Nb = GetLastError();
sprintf(Val2, "Error", "%d", Nb);
MessageBox(NULL, Val2, NULL, MB_OK);

}
else
{
if (C == 32)
{
Tab [j] [i] = '\0';
i = 0;
j++;
}
else
{
Tab [j] [i] = C;
i++;
}
}

}
CloseHandle(h);
Tab [j] [i] = '\0';
j = 0;

while (j < 25 && Tab [j] != NULL && !WordFound )
{
if (Tab [j] == WordToFind) //False if Tab[j] ="Hello" and WordToFind = "Hello" ... I dont get it
{
WordFound == true;
}
else
{
j++;
}
}

if WordFound == true)
{
MessageBox(NULL, "Found", NULL, MB_OK);
}
else
{
MessageBox(NULL, "Not Found", NULL, MB_OK);
}
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll