Skip to content

Comments

commits from the first rewrite#25

Open
Andrw-404 wants to merge 3 commits intomainfrom
verificationWorks
Open

commits from the first rewrite#25
Andrw-404 wants to merge 3 commits intomainfrom
verificationWorks

Conversation

@Andrw-404
Copy link
Owner

No description provided.

…р, 12321 является, а 123421 нет. Функция принимает на вход аргумент типа int и возвращает ответ типа bool.
…довательность повторяющихся символов одним символом. Например, aafgbbba должно выводиться как afgba.
@Andrw-404 Andrw-404 changed the title Write a function to check if a number is a palindrome. commits from the first rewrite Nov 1, 2024
#include <string.h>

bool removingDuplicateCharacters(const char* filename, char* output) {
FILE* file = fopen(filename, "r");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Используйте четыре пробела вместо табуляции для отступов

#include <stdbool.h>
#include <string.h>

bool removingDuplicateCharacters(const char* filename, char* output) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Функции именуются глаголом в повелительной форме, правильно не removing, а remove

perror("elementsForTask.txt");
return false;
}
char current = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fgetc возвращает int, так что current тоже должен бы int-овым быть


while ((current = fgetc(file)) != EOF) {
if (current != last) {
output[index++] = current;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Побочные эффекты в выражениях мы не приветствуем.

Suggested change
output[index++] = current;
output[index] = current;
index++;

Так по идее более читаемо, потому что сложнее пропустить, что с index что-то происходит ещё.

Comment on lines +31 to +40
char output[100] = " ";
char* testFilename = "fileForTask.txt";
const char* expected = "afgba";
if (!removingDuplicateCharacters(testFilename, output)) {
return 1;
}
if (!checkOutput(output, expected)) {
printf("Ошибка\n");
return 1;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Вообще это код теста, так что должен бы быть вынесен в отдельную функцию.

Comment on lines +23 to +25
if (number < 0) {
return false;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

На паре голосом пояснял, что отрицательное число считается палиндромом, если его модуль является палиндромом, но окей, в условии этого не было

return 1;
}
char inputString[100] = " ";
int number = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Объявили бы его на 74-й строчке

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants