From 1d1aad9cf98452c3bb2048de02038afd46e29ec5 Mon Sep 17 00:00:00 2001 From: Artem Date: Wed, 21 Dec 2022 16:59:10 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=97=D0=B0=D0=B4=D0=B0=D1=87=D0=B0=20?= =?UTF-8?q?=D1=81=20=D0=B7=D0=B0=D1=87=D1=91=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../offsetSecondTryThirdTask.sln | 31 ++++ .../offsetSecondTryThirdTask/lexer.c | 122 ++++++++++++++ .../offsetSecondTryThirdTask/lexer.h | 13 ++ .../offsetSecondTryThirdTask/main.c | 41 +++++ .../offsetSecondTryThirdTask.vcxproj | 154 ++++++++++++++++++ .../offsetSecondTryThirdTask.vcxproj.filters | 35 ++++ .../offsetSecondTryThirdTask/test.txt | 1 + 7 files changed, 397 insertions(+) create mode 100644 offsetSecondTryThirdTask/offsetSecondTryThirdTask.sln create mode 100644 offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c create mode 100644 offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.h create mode 100644 offsetSecondTryThirdTask/offsetSecondTryThirdTask/main.c create mode 100644 offsetSecondTryThirdTask/offsetSecondTryThirdTask/offsetSecondTryThirdTask.vcxproj create mode 100644 offsetSecondTryThirdTask/offsetSecondTryThirdTask/offsetSecondTryThirdTask.vcxproj.filters create mode 100644 offsetSecondTryThirdTask/offsetSecondTryThirdTask/test.txt diff --git a/offsetSecondTryThirdTask/offsetSecondTryThirdTask.sln b/offsetSecondTryThirdTask/offsetSecondTryThirdTask.sln new file mode 100644 index 0000000..300ddbb --- /dev/null +++ b/offsetSecondTryThirdTask/offsetSecondTryThirdTask.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "offsetSecondTryThirdTask", "offsetSecondTryThirdTask\offsetSecondTryThirdTask.vcxproj", "{ECA430AB-37C1-4EC6-BFF6-BB81509B4043}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {ECA430AB-37C1-4EC6-BFF6-BB81509B4043}.Debug|x64.ActiveCfg = Debug|x64 + {ECA430AB-37C1-4EC6-BFF6-BB81509B4043}.Debug|x64.Build.0 = Debug|x64 + {ECA430AB-37C1-4EC6-BFF6-BB81509B4043}.Debug|x86.ActiveCfg = Debug|Win32 + {ECA430AB-37C1-4EC6-BFF6-BB81509B4043}.Debug|x86.Build.0 = Debug|Win32 + {ECA430AB-37C1-4EC6-BFF6-BB81509B4043}.Release|x64.ActiveCfg = Release|x64 + {ECA430AB-37C1-4EC6-BFF6-BB81509B4043}.Release|x64.Build.0 = Release|x64 + {ECA430AB-37C1-4EC6-BFF6-BB81509B4043}.Release|x86.ActiveCfg = Release|Win32 + {ECA430AB-37C1-4EC6-BFF6-BB81509B4043}.Release|x86.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A3E58929-7DA2-483A-BCCE-589854B4EF84} + EndGlobalSection +EndGlobal diff --git a/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c new file mode 100644 index 0000000..afa5c15 --- /dev/null +++ b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c @@ -0,0 +1,122 @@ +#include "lexer.h" +#include +#include +#include +#include + +typedef enum Stage { + first, + second, + third, + fourth, + fifth +} Stage; + +char* workWithFileAndReturnString(const char* nameFile, Error* errorCheck) { + FILE* file = fopen(nameFile, "r"); + if (file == NULL) { + *errorCheck = errorWithFile; + return NULL; + } + char buffer[1000] = { '\0' }; + char result[10000] = { '\0' }; + Stage stage = first; + char symbol = 0; + int indexBuffer = 0; + bool isNeedAddLast = false; + while (fscanf(file, "%c", &symbol) == 1) { + switch (stage) + { + case first: + if (symbol >= 'A' && symbol <= 'Z' || symbol == '+' || symbol == '-' + || symbol >= '0' && symbol <= '9' || symbol == '.' || symbol == '%') { + buffer[indexBuffer] = symbol; + ++indexBuffer; + stage = first; + } + else if (symbol == '@') { + buffer[indexBuffer] = symbol; + ++indexBuffer; + stage = second; + } + else { + memset(buffer, 0, strlen(buffer)); + indexBuffer = 0; + stage = first; + } + break; + case second: + if (symbol >= 'A' && symbol <= 'Z' + || symbol >= '0' && symbol <= '9' || symbol == '-') { + buffer[indexBuffer] = symbol; + ++indexBuffer; + stage = third; + } else { + memset(buffer, 0, strlen(buffer)); + indexBuffer = 0; + stage = first; + } + break; + case third: + if (symbol >= 'A' && symbol <= 'Z' + || symbol >= '0' && symbol <= '9' || symbol == '-') { + buffer[indexBuffer] = symbol; + ++indexBuffer; + stage = third; + } + else if (symbol == '.') { + buffer[indexBuffer] = symbol; + ++indexBuffer; + stage = fourth; + } + else { + memset(buffer, 0, strlen(buffer)); + indexBuffer = 0; + stage = first; + } + break; + case fourth: + if (symbol >= 'A' && symbol <= 'Z') { + buffer[indexBuffer] = symbol; + ++indexBuffer; + stage = fifth; + isNeedAddLast = true; + } else if (symbol >= '0' && symbol <= '9' || symbol == '-') { + buffer[indexBuffer] = symbol; + ++indexBuffer; + stage = third; + } else { + memset(buffer, 0, strlen(buffer)); + indexBuffer = 0; + stage = first; + } + break; + case fifth: + if (symbol >= '0' && symbol <= '9' || symbol == '-' || symbol == '.') { + buffer[indexBuffer] = symbol; + ++indexBuffer; + stage = fourth; + isNeedAddLast = false; + break; + } else { + strcat(result, buffer); + memset(buffer, 0, strlen(buffer)); + indexBuffer = 0; + if (symbol >= 'A' && symbol <= 'Z' || symbol == '+' || symbol == '-' + || symbol >= '0' && symbol <= '9' || symbol == '.' || symbol == '%') { + buffer[indexBuffer] = symbol; + ++indexBuffer; + stage = first; + } + stage = first; + isNeedAddLast = false; + } + break; + } + } + if (isNeedAddLast) { + strcat(result, buffer); + } + fclose(file); + return result; +} \ No newline at end of file diff --git a/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.h b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.h new file mode 100644 index 0000000..ea82992 --- /dev/null +++ b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +//Variable for error checking +typedef enum Error { + ok, + errorWithFile, + anotherError +} Error; + +//return string with emails +char* workWithFileAndReturnString(const char* nameFile, Error* errorCheck); \ No newline at end of file diff --git a/offsetSecondTryThirdTask/offsetSecondTryThirdTask/main.c b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/main.c new file mode 100644 index 0000000..e934c65 --- /dev/null +++ b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/main.c @@ -0,0 +1,41 @@ +#include "lexer.h" +#include +#include +#include +#include + +bool test() { + char nameFile[] = "test.txt"; + char trueAnswer[] = "A.%@A9.A"; + Error errorCheck = ok; + char* result = workWithFileAndReturnString(nameFile, &errorCheck); + if (errorCheck != ok) { + return false; + } + return strcmp(trueAnswer, result) == 0; +} + +int main() { + if (test()) { + printf("Test correct\n"); + } else { + printf("Error\n"); + return -1; + } + printf("Write the name of the file with its extension. No more than 99 symbols\n"); + char nameFile[100] = { '\0' }; + int checkScanf = scanf("%s", nameFile); + while (checkScanf != 1) { + while (getchar() != '\n') { + } + + checkScanf = scanf("%s", nameFile); + } + Error errorCheck = ok; + char* result = workWithFileAndReturnString(nameFile, &errorCheck); + if (errorCheck != ok) { + printf("Error\n"); + return -1; + } + printf("%s\n", result); +} \ No newline at end of file diff --git a/offsetSecondTryThirdTask/offsetSecondTryThirdTask/offsetSecondTryThirdTask.vcxproj b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/offsetSecondTryThirdTask.vcxproj new file mode 100644 index 0000000..bb0f89f --- /dev/null +++ b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/offsetSecondTryThirdTask.vcxproj @@ -0,0 +1,154 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 16.0 + Win32Proj + {eca430ab-37c1-4ec6-bff6-bb81509b4043} + offsetSecondTryThirdTask + 10.0 + + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + Application + true + v143 + Unicode + + + Application + false + v143 + true + Unicode + + + + + + + + + + + + + + + + + + + + + true + + + false + + + true + + + false + + + + Level3 + true + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + Level3 + false + _DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + + + + + Level3 + true + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + + + Console + true + true + true + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/offsetSecondTryThirdTask/offsetSecondTryThirdTask/offsetSecondTryThirdTask.vcxproj.filters b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/offsetSecondTryThirdTask.vcxproj.filters new file mode 100644 index 0000000..9492cbd --- /dev/null +++ b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/offsetSecondTryThirdTask.vcxproj.filters @@ -0,0 +1,35 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Исходные файлы + + + Исходные файлы + + + + + Исходные файлы + + + + + Исходные файлы + + + \ No newline at end of file diff --git a/offsetSecondTryThirdTask/offsetSecondTryThirdTask/test.txt b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/test.txt new file mode 100644 index 0000000..3005de0 --- /dev/null +++ b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/test.txt @@ -0,0 +1 @@ +A.%@A9.A]AB.%@@A9.A0@.F \ No newline at end of file From d685ca3224772234825d0e969c803508108efd99 Mon Sep 17 00:00:00 2001 From: Artem Date: Wed, 21 Dec 2022 17:04:58 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B2=20=D1=81=D0=BE=D1=81=D1=82=D0=BE=D1=8F?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c index afa5c15..638554e 100644 --- a/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c +++ b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c @@ -92,12 +92,16 @@ char* workWithFileAndReturnString(const char* nameFile, Error* errorCheck) { } break; case fifth: - if (symbol >= '0' && symbol <= '9' || symbol == '-' || symbol == '.') { + if (symbol >= '0' && symbol <= '9' || symbol == '-') { + buffer[indexBuffer] = symbol; + ++indexBuffer; + stage = third; + isNeedAddLast = false; + } else if (symbol == '.') { buffer[indexBuffer] = symbol; ++indexBuffer; stage = fourth; isNeedAddLast = false; - break; } else { strcat(result, buffer); memset(buffer, 0, strlen(buffer)); From 0558e4123cbab9a98f78e05e29f87139b1e2aa4d Mon Sep 17 00:00:00 2001 From: Artem Date: Wed, 21 Dec 2022 17:10:26 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20=D1=81=D0=BE=D1=81=D1=82=D0=BE=D1=8F?= =?UTF-8?q?=D0=BD=D0=B8=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../offsetSecondTryThirdTask/lexer.c | 39 ++++++++++++------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c index 638554e..c1d3ec0 100644 --- a/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c +++ b/offsetSecondTryThirdTask/offsetSecondTryThirdTask/lexer.c @@ -9,7 +9,8 @@ typedef enum Stage { second, third, fourth, - fifth + fifth, + sixth } Stage; char* workWithFileAndReturnString(const char* nameFile, Error* errorCheck) { @@ -32,42 +33,54 @@ char* workWithFileAndReturnString(const char* nameFile, Error* errorCheck) { || symbol >= '0' && symbol <= '9' || symbol == '.' || symbol == '%') { buffer[indexBuffer] = symbol; ++indexBuffer; + stage = second; + } else { + memset(buffer, 0, strlen(buffer)); + indexBuffer = 0; stage = first; } - else if (symbol == '@') { + break; + case second: + if (symbol >= 'A' && symbol <= 'Z' || symbol == '+' || symbol == '-' + || symbol >= '0' && symbol <= '9' || symbol == '.' || symbol == '%') { buffer[indexBuffer] = symbol; ++indexBuffer; stage = second; } + else if (symbol == '@') { + buffer[indexBuffer] = symbol; + ++indexBuffer; + stage = third; + } else { memset(buffer, 0, strlen(buffer)); indexBuffer = 0; stage = first; } break; - case second: + case third: if (symbol >= 'A' && symbol <= 'Z' || symbol >= '0' && symbol <= '9' || symbol == '-') { buffer[indexBuffer] = symbol; ++indexBuffer; - stage = third; + stage = fourth; } else { memset(buffer, 0, strlen(buffer)); indexBuffer = 0; stage = first; } break; - case third: + case fourth: if (symbol >= 'A' && symbol <= 'Z' || symbol >= '0' && symbol <= '9' || symbol == '-') { buffer[indexBuffer] = symbol; ++indexBuffer; - stage = third; + stage = fourth; } else if (symbol == '.') { buffer[indexBuffer] = symbol; ++indexBuffer; - stage = fourth; + stage = fifth; } else { memset(buffer, 0, strlen(buffer)); @@ -75,32 +88,32 @@ char* workWithFileAndReturnString(const char* nameFile, Error* errorCheck) { stage = first; } break; - case fourth: + case fifth: if (symbol >= 'A' && symbol <= 'Z') { buffer[indexBuffer] = symbol; ++indexBuffer; - stage = fifth; + stage = sixth; isNeedAddLast = true; } else if (symbol >= '0' && symbol <= '9' || symbol == '-') { buffer[indexBuffer] = symbol; ++indexBuffer; - stage = third; + stage = fourth; } else { memset(buffer, 0, strlen(buffer)); indexBuffer = 0; stage = first; } break; - case fifth: + case sixth: if (symbol >= '0' && symbol <= '9' || symbol == '-') { buffer[indexBuffer] = symbol; ++indexBuffer; - stage = third; + stage = fourth; isNeedAddLast = false; } else if (symbol == '.') { buffer[indexBuffer] = symbol; ++indexBuffer; - stage = fourth; + stage = fifth; isNeedAddLast = false; } else { strcat(result, buffer);