So here is my input
\\?\usb#vid_04d9&pid_1702#6&12e3c9ed&0&2#{a5dcbf10-6530-11d2-901f-00c04fb951ed}
I need to extract 04d9 and 1702 from this string. Instead of copying the values I just point my pointer to their respective locations.
And here is my horrible code
#DEFINE FIRST_STRING 1
#DEFINE SECOND_STRING 2
#DEFINE THIRD_STRING 3
VOID
StringDelimiterReplace(
PCHAR string,
INT delimiter,
INT replace
)
/*
Description:
Replaces the delimiter in the string with the replace value specified
*/
{
size_t stringLen = strlen(string);
for (size_t size = 0; size < stringLen; size++) {
if (string[size] == delimiter) string[size] = replace;
}
}
VOID
GenericStringSplit(
PCHAR string,
INT delimiter,
PCHAR *dest,
INT tokenNum,
INT replace
)
/*
Description:
A generic string splitting function which returns the string at token number
specified,
Also provision to replace the delimiter with string
*/
{
int i = 1;
size_t size;
if( delimiter != replace) StringDelimiterReplace(string, delimiter, replace);
if (tokenNum == 1) *dest = string;
for (size = 0; ; size++) {
if (string[size] != replace) continue;
if (i == tokenNum - 1) break;
if (i > tokenNum - 1) return;
i++;
}
*dest = &string[++size];
}
//main
GenericStringSplit(string, '#', &dest, SECOND_STRING, '\0');
GenericStringSplit(dest, '&', &vendorId, FIRST_STRING, '\0');
GenericStringSplit(dest, '\0', &productId, SECOND_STRING, '\0');
GenericStringSplit(vendorId, '_', &vendorId, SECOND_STRING, '\0');
GenericStringSplit(productId, '_', &productId, SECOND_STRING, '\0');
VOID,PCHARetc. Did you omit some typedefs? \$\endgroup\$<Windows.h>as everyone suggested I should not be using those \$\endgroup\$