typedef struct {
char algo[4];
char salt[65];
char hash_pwd[192];
} pwd_info;
void split_string(char *input, char delimiter, pwd_info* res)
{
char *start = input;
char *end;
char array_res[3][192];
memset(&array_res, 0, sizeof(array_res));
int i = 0;
if (*start != '\0') { // ignore first $
start = start + 1;
}
while (*start != '\0') {
// 找到分隔符的位置
end = start;
while (*end != delimiter && *end != '\0') {
end++;
}
// 计算子字符串的长度
size_t length = end - start;
// 复制子字符串
strncpy(array_res[i], start, length);
printf("%s\n", array_res[i]);
array_res[i++][length] = '\0';
if (i >2) {
printf("to many $\n");
break;
}
// 如果遇到分隔符,移动到分隔符之后的位置
if (*end == delimiter) {
start = end + 1;
} else {
// 到达字符串末尾,退出循环
break;
}
}
strncpy(res->algo, array_res[0], sizeof(res->algo) - 1);
strncpy(res->salt, array_res[1], sizeof(res->salt) - 1);
strncpy(res->hash_pwd, array_res[2], sizeof(res->hash_pwd) - 1);
}