|
@@ -1,6 +1,8 @@
|
|
|
+#define _CRT_SECURE_NO_WARNINGS
|
|
|
#include <windows.h>
|
|
|
#include <stdio.h>
|
|
|
#include <malloc.h>
|
|
|
+#include <string.h>
|
|
|
#include "../structs.h"
|
|
|
|
|
|
BOOL WINAPI DllMain(HINSTANCE hlnstDll, DWORD dwReason, LPVOID IpReserved)
|
|
@@ -31,31 +33,79 @@ BOOL WINAPI DllMain(HINSTANCE hlnstDll, DWORD dwReason, LPVOID IpReserved)
|
|
|
// MessageBox(NULL, str, L"ß äà", MB_OK);
|
|
|
// return 0;
|
|
|
//}
|
|
|
-extern "C" __declspec(dllimport) ResultUserAndCount* GetFirstAndCounter(HANDLE file_read);
|
|
|
-ResultUserAndCount* GetFirstAndCounter(HANDLE file_read) {
|
|
|
- ResultUserAndCount* result = (ResultUserAndCount*)malloc(sizeof(ResultUserAndCount));
|
|
|
+int Convert_sub(char* sub) {
|
|
|
+ int result = 0;
|
|
|
+ int ymnoz = 1;
|
|
|
+ for (size_t i = 0; i < strlen(sub); i++)
|
|
|
+ {
|
|
|
+ result *= ymnoz;
|
|
|
+ result += sub[i] - '0';
|
|
|
+ ymnoz *= 10;
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+}
|
|
|
|
|
|
+extern "C" __declspec(dllimport) ResultUserAndCount GetFirstAndCounter(FILE* file_read);
|
|
|
+ResultUserAndCount GetFirstAndCounter(FILE* file_read) {
|
|
|
+ ResultUserAndCount result = { NULL, 0 };
|
|
|
+ User* list_user = (User*)malloc(sizeof(User) * 200);
|
|
|
char* buffer = (char*)malloc(sizeof(char) * 100);
|
|
|
- DWORD count_buff = 100;
|
|
|
- DWORD count_char = 0;
|
|
|
- while (ReadFile(
|
|
|
- file_read,
|
|
|
- buffer + (count_buff - 100),
|
|
|
- count_buff,
|
|
|
- &count_char,
|
|
|
- NULL
|
|
|
- ) && count_char > 0) {
|
|
|
- count_buff += 100;
|
|
|
- buffer = (char*)realloc(buffer, sizeof(char) * count_buff);
|
|
|
+ int index_start = 0;
|
|
|
+ int index_list = 0;
|
|
|
+ int count_user = 0;
|
|
|
+ int count_sub_char = 0;
|
|
|
+ while (fscanf(file_read, "%s", buffer) == 1) {
|
|
|
+ for (size_t i = 0; i < strlen(buffer); i++)
|
|
|
+ {
|
|
|
+ if (buffer[i] != '\r' && buffer[i] != '\n' && buffer[i] != '\"') {
|
|
|
+ if (buffer[i] == ';')
|
|
|
+ {
|
|
|
+ char* sub = (char*)malloc(sizeof(char) * 100);
|
|
|
+ int index_sub = 0;
|
|
|
+ for (size_t j = index_start + 1; j < i; j++)
|
|
|
+ {
|
|
|
+ sub[index_sub] = buffer[j];
|
|
|
+ index_sub++;
|
|
|
+ }
|
|
|
+ sub[index_sub] = '\0';
|
|
|
+ index_start = i;
|
|
|
+ switch (count_sub_char)
|
|
|
+ {
|
|
|
+ case 0:
|
|
|
+ list_user[index_list].last_name = sub;
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ list_user[index_list].first_name = sub;
|
|
|
+ break;
|
|
|
+ case 2:
|
|
|
+ list_user[index_list].patrinymic = sub;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ count_sub_char++;
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (buffer[i] == '\"' && count_sub_char != 0) {
|
|
|
+ char* sub = (char*)malloc(sizeof(char) * 100);
|
|
|
+ int index_sub = 0;
|
|
|
+ for (size_t j = index_start + 1; j < i; j++)
|
|
|
+ {
|
|
|
+ sub[index_sub] = buffer[j];
|
|
|
+ index_sub++;
|
|
|
+ }
|
|
|
+ sub[index_sub] = '\0';
|
|
|
+ list_user[index_list].age = Convert_sub(sub);
|
|
|
+ count_sub_char = 0;
|
|
|
+ index_start = 0;
|
|
|
+ index_list++;
|
|
|
+ count_user++;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
- CloseHandle(file_read);
|
|
|
- printf("%s", buffer);
|
|
|
- result->count_users = 1;
|
|
|
- result->user = (User*)malloc(sizeof(User));
|
|
|
- result->user->last_name = _strdup("Ïðèìåð");
|
|
|
- result->user->first_name = _strdup("Ôàìèëèÿ");
|
|
|
- result->user->patrinymic = _strdup("Îò÷åñòâî");
|
|
|
- result->user->age = 0; //Èëè êàêîå-òî çíà÷åíèå ïî óìîë÷àíèþ
|
|
|
+ result.count_users = count_user;
|
|
|
+ result.user = list_user[0];
|
|
|
return result;
|
|
|
}
|