Conversation
…р, 12321 является, а 123421 нет. Функция принимает на вход аргумент типа int и возвращает ответ типа bool.
…довательность повторяющихся символов одним символом. Например, aafgbbba должно выводиться как afgba.
| #include <string.h> | ||
|
|
||
| bool removingDuplicateCharacters(const char* filename, char* output) { | ||
| FILE* file = fopen(filename, "r"); |
There was a problem hiding this comment.
Используйте четыре пробела вместо табуляции для отступов
| #include <stdbool.h> | ||
| #include <string.h> | ||
|
|
||
| bool removingDuplicateCharacters(const char* filename, char* output) { |
There was a problem hiding this comment.
Функции именуются глаголом в повелительной форме, правильно не removing, а remove
| perror("elementsForTask.txt"); | ||
| return false; | ||
| } | ||
| char current = 0; |
There was a problem hiding this comment.
fgetc возвращает int, так что current тоже должен бы int-овым быть
|
|
||
| while ((current = fgetc(file)) != EOF) { | ||
| if (current != last) { | ||
| output[index++] = current; |
There was a problem hiding this comment.
Побочные эффекты в выражениях мы не приветствуем.
| output[index++] = current; | |
| output[index] = current; | |
| index++; |
Так по идее более читаемо, потому что сложнее пропустить, что с index что-то происходит ещё.
| 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; | ||
| } |
There was a problem hiding this comment.
Вообще это код теста, так что должен бы быть вынесен в отдельную функцию.
| if (number < 0) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
На паре голосом пояснял, что отрицательное число считается палиндромом, если его модуль является палиндромом, но окей, в условии этого не было
| return 1; | ||
| } | ||
| char inputString[100] = " "; | ||
| int number = 0; |
No description provided.