M
marcwentink
I wonder if there is no other way to substract a substring from a
string then just using a while lus. This below works ok, but looks like
a lot of code and statements if I compare it with the use of
std::string. Is this a bit ok? It should get information from a HTTP
request between the chars "GET /" and "HTTP".
Trying to combine <string> and "*.h" C includes and compiling "C++"
instead of just "C" also lead to a disaster, so that alternative does
not look appealing either.
Here is my code:
void getInfo(const char * pszBuf, char * pstrOms, char * pstrAGB, char
* pstrCat, char * pstrPIN)
{
char * afterGETSLASH = strstr(pszBuf, "GET /");
afterGETSLASH = strchr(afterGETSLASH, '[');afterGETSLASH++;
char* pStrHTTP = NULL;
pStrHTTP = strstr(afterGETSLASH, "HTTP");
pStrHTTP--;
int i=0;
while ( (afterGETSLASH != pStrHTTP) && (*afterGETSLASH != ',') &&
(*afterGETSLASH != ']') )
{
pstrOms=*afterGETSLASH;
i++;
afterGETSLASH++;
}
afterGETSLASH++;
i=0;
while ( (afterGETSLASH != pStrHTTP) && (*afterGETSLASH != ',') &&
(*afterGETSLASH != ']') )
{
pstrAGB=*afterGETSLASH;
i++;
afterGETSLASH++;
}
afterGETSLASH++;
i=0;
while ( (afterGETSLASH != pStrHTTP) && (*afterGETSLASH != ',') &&
(*afterGETSLASH != ']') )
{
pstrCat=*afterGETSLASH;
i++;
afterGETSLASH++;
}
afterGETSLASH++;
i=0;
while ( (afterGETSLASH != pStrHTTP) && (*afterGETSLASH != ',') &&
(*afterGETSLASH != ']') )
{
pstrPIN=*afterGETSLASH;
i++;
afterGETSLASH++;
}
}
string then just using a while lus. This below works ok, but looks like
a lot of code and statements if I compare it with the use of
std::string. Is this a bit ok? It should get information from a HTTP
request between the chars "GET /" and "HTTP".
Trying to combine <string> and "*.h" C includes and compiling "C++"
instead of just "C" also lead to a disaster, so that alternative does
not look appealing either.
Here is my code:
void getInfo(const char * pszBuf, char * pstrOms, char * pstrAGB, char
* pstrCat, char * pstrPIN)
{
char * afterGETSLASH = strstr(pszBuf, "GET /");
afterGETSLASH = strchr(afterGETSLASH, '[');afterGETSLASH++;
char* pStrHTTP = NULL;
pStrHTTP = strstr(afterGETSLASH, "HTTP");
pStrHTTP--;
int i=0;
while ( (afterGETSLASH != pStrHTTP) && (*afterGETSLASH != ',') &&
(*afterGETSLASH != ']') )
{
pstrOms=*afterGETSLASH;
i++;
afterGETSLASH++;
}
afterGETSLASH++;
i=0;
while ( (afterGETSLASH != pStrHTTP) && (*afterGETSLASH != ',') &&
(*afterGETSLASH != ']') )
{
pstrAGB=*afterGETSLASH;
i++;
afterGETSLASH++;
}
afterGETSLASH++;
i=0;
while ( (afterGETSLASH != pStrHTTP) && (*afterGETSLASH != ',') &&
(*afterGETSLASH != ']') )
{
pstrCat=*afterGETSLASH;
i++;
afterGETSLASH++;
}
afterGETSLASH++;
i=0;
while ( (afterGETSLASH != pStrHTTP) && (*afterGETSLASH != ',') &&
(*afterGETSLASH != ']') )
{
pstrPIN=*afterGETSLASH;
i++;
afterGETSLASH++;
}
}