Re: Input file *.txt to dialog box
From: Jase (jshelley_at_nospam.optushome.com.au)
Date: 03/30/04
- Next message: Gary Chang: "Re: Disable Linker Warnings"
- Previous message: TVR Fan: "Re: Some difficulty in my project"
- In reply to: Ray Schmidt: "Re: Input file *.txt to dialog box"
- Next in thread: Jase: "Re: Input file *.txt to dialog box"
- Reply: Jase: "Re: Input file *.txt to dialog box"
- Messages sorted by: [ date ] [ thread ]
Date: Tue, 30 Mar 2004 19:32:53 +1000
Here's how you search for a complete string. Firstly, store the string you
are searching for in a char array. You will also need a pointer to the
current character in the string. Then, you loop through the stream,
searching for each character in turn, incrementing the current character
pointer each time. Here's a bit of code that will be much easier to
understand ;-) Using the MFC class CFile rather than stdio functions.
char szMatch[] = "[FoundSection]\r\n";
char * cur = szMatch; // cur now points to the first character
char ch;
CString strOut;
// assumes the CFile object f has been opened with read privileges
CArchive ar(&f, CArchive::load); // use CArchive as it provides buffering
for faster single char access
while (ar.Read(&ch, 1)) {
if (cur == szMatch) { // we're not in a match
if (ch == *cur)
cur++;
} else {
if (ch == *cur) {
cur++;
if (*cur == '\0') {
// complete string match
break;
}
} else
cur = szMatch; // incomplete match. Reset.
}
}
if (*cur == '\0') { // string matched
while (ar.Read(&ch, 1)) {
if (ch == '\r') // if this is the first of a /r/n, which are two
characters, btw
break;
strOut += ch;
}
m_edit.SetWindowText(strOut); // m_edit is a CEdit variable created
in the class wizard
} else {
// section not found
}
Jase
"Ray Schmidt" <raymondschmidt@bellsouth.net> wrote in message
news:173F7624-3FB4-4381-BE70-134E21DDB70B@microsoft.com...
> Because I'm ignorant and not sure how to test for then entire string to
match that condition. I keep trying to sequentally read down each char:
>
> for( i = 0; (i < 80) && ((ch = getchar()) != EOF)
> && (ch = '\r\n'); i++ )
> {
>
> buffer[i] = (char)ch;
> ch = fgetc( *stream );
> }
>
> Please, I'm sure this looks like silly mistake, however, I'm trying...
>
>
>
>
- Next message: Gary Chang: "Re: Disable Linker Warnings"
- Previous message: TVR Fan: "Re: Some difficulty in my project"
- In reply to: Ray Schmidt: "Re: Input file *.txt to dialog box"
- Next in thread: Jase: "Re: Input file *.txt to dialog box"
- Reply: Jase: "Re: Input file *.txt to dialog box"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|