Download Programming with lcc-win32
Transcript
210
C programming with lcc-win32
2.3.8
Searching text
The Strstr searches a pattern in a given string, and returns a fat pointer to a string (Stringp), or
an invalid string if not found.
Stringp overloaded Strstr(String & string, String & find_this)
{
char *strp,*end;
int first_char,r;
struct Exception *exc = GetAnExceptionStructure();
PRECONDITION ((Strvalid(string) && Strvalid(find_this)), exc);
first_char = find_this.content[0];
strp = memchr(string.content,first_char,string.count);
if (strp) {
end = string.content + string.count;
while (strp < end) {
if (!memcmp(strp,find_this.content,find_this.count))
return new_stringp(string,strp);
else
strp++;
}
}
return invalid_stringp;
}
We search the first character of the string to search in the string. Each time we find it, we test
if the search pattern is there. If yes we return a new string pointer, otherwise we go on until we
reach the end of the string.
To search a character in a string we use the Strchr function:
Stringp overloaded Strchr(String & string, int element)
{
struct Exception *exc = GetAnExceptionStructure();
PRECONDITION((Strvalid(string)), exc);
char *p = memchr(string.content,element,string.count);
if (p){ // found
return new_stringp(string,p);
}
return invalid_stringp;
}
2.3.9
Making a string from a pipe
The function Strfrompipe will start a program and capture all its textual output into a String.
This is useful for many GUI applications that want to show the results of a program in a different way, and many others.
The algorithm used is very simple: we start the command indicated in the string argument with
the process using a redirected standard output into a temporary file. We read then this file into
a string a return the result.
StringA overloaded Strfrompipe(String &Cmdline)
{
STARTUPINFO startInfo;
char *p;
int processStarted,m;
String result = invalidStringA;
HANDLE hWritePipe;
LPSECURITY_ATTRIBUTES lpsa=NULL;
SECURITY_ATTRIBUTES sa;
Related documents
Programming with lcc
Programming with lcc-win
C-Tutorial
Manuel d`utilisation de Version 1.3
IOTech Personal488 DOS and Windows3.X User Manual
WinCE manual for OEM - Future Design Controls
E SPOT III User Manual ver 1
Platinum Spot III User Manual ver 1
Platinum SBX User Manual ver 1
Cygwin User's Guide
OmniFlop User Guide
Cygwin User's Guide