-
Notifications
You must be signed in to change notification settings - Fork 0
Сделал всё #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Сделал всё #3
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,73 @@ | ||||||
| #include <stdio.h> | ||||||
| #include <stdlib.h> | ||||||
| #include <locale.h> | ||||||
| #include <string.h> | ||||||
| #include <stdbool.h> | ||||||
|
|
||||||
| bool scanFile(char fileName[], char arrayForTest[]) { | ||||||
| FILE* file = fopen(fileName, "r"); | ||||||
| if (file == NULL) { | ||||||
| printf("Mistake!"); | ||||||
| return false; | ||||||
| } | ||||||
| char data[100] = { '\0' }; | ||||||
| int pointerTest = 0; | ||||||
| while (fscanf(file, "%s", data) == 1){ | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| size_t sizeData = strlen(data); | ||||||
| if (sizeData >= 1) { | ||||||
| if (fileName != NULL && strcmp(fileName, "test.txt") != 0) { | ||||||
| printf("%c", data[0]); | ||||||
| } else { | ||||||
| if (arrayForTest[pointerTest] != data[0]) { | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вообще, в боевом коде не должно быть ничего про тесты. Тест должен тестировать наблюдаемое извне поведение настоящего кода, а не какой-то кастомный код, написанный специально под тест в реальной системе. |
||||||
| return false; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Файл останется незакрытым |
||||||
| } | ||||||
| ++pointerTest; | ||||||
| } | ||||||
| } | ||||||
| for (size_t i = 1; i < sizeData; ++i) { | ||||||
| if (data[i] != data[i - 1]) { | ||||||
| if (fileName != NULL && strcmp(fileName, "test.txt") != 0) { | ||||||
| printf("%c", data[i]); | ||||||
| } else { | ||||||
| if (arrayForTest[pointerTest] != data[i]) { | ||||||
| return false; | ||||||
| } | ||||||
| ++pointerTest; | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| } | ||||||
| fclose(file); | ||||||
| return true; | ||||||
| } | ||||||
|
|
||||||
| bool test(){ | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| char fileName[9] = "test.txt"; | ||||||
| char arrayTest[4] = "abc"; | ||||||
| return scanFile(fileName, arrayTest); | ||||||
|
Comment on lines
+45
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Вот если бы scanFile принимала const-ы, то эти переменные были бы не нужны |
||||||
| } | ||||||
|
|
||||||
| int main(void) { | ||||||
| setlocale(LC_ALL, "RUS"); | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Что-то тут отступов многовато |
||||||
| if (test()) { | ||||||
| printf("Tests correct\n"); | ||||||
| } | ||||||
| else { | ||||||
| printf("Mistake...\n"); | ||||||
| return 0; | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| } | ||||||
| printf("Enter the file name and its extension, the size should not exceed 100 characters. You cannot enter a file named test.txt.\n"); | ||||||
| char fileName[100] = { '\0' }; | ||||||
| int checkScan = scanf("%s", &fileName); | ||||||
|
|
||||||
| while (checkScan != 1 || fileName == NULL || strcmp(fileName, "test.txt") == 0) { | ||||||
| while (getchar() != '\n') { | ||||||
| } | ||||||
| printf("Mistake...Try again\n"); | ||||||
| checkScan = scanf("%s", &fileName); | ||||||
| } | ||||||
| if (!scanFile(fileName, NULL)) { | ||||||
| printf("Mistake...\n"); | ||||||
| return -1; | ||||||
| } | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| aabbcc |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Мы их вроде ниже не меняем