Skip to content

Working with lesson_3_branch.#4

Open
yaprogrammer18-yanchi wants to merge 18 commits into
mainfrom
lesson_3_branch
Open

Working with lesson_3_branch.#4
yaprogrammer18-yanchi wants to merge 18 commits into
mainfrom
lesson_3_branch

Conversation

@yaprogrammer18-yanchi

Copy link
Copy Markdown
Owner

Добавила файлы домашней работы от урока о Компиляции. Удалила папку самого урока чтобы не путаться. Теперь все файлы лежат только в src.

@WoWaster WoWaster left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Общее замечание: вынесите всю логику в отдельные функции. Ну и посмотрите, какие комментарии правда нужны.

Comment thread src/bracketBalance.c Outdated

int main()
{
int* stackForBrackets = calloc(100, sizeof(int)); // сделаем большой стек состоящий из 100 нулей

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Писать комментарии --- отдельное искусство.
Но для начала есть два простых правила:

  1. Пишите комментарии над сущностью, которую комментируете.
  2. Если комментарий описывает ровно то, что написано в коде --- он не нужен.

Comment thread src/bracketBalance.c Outdated
scanf("%100[^\n]", stringWithBrackets); // ввели строку (огранчение 100 символов)

int count = 0; // счетчик того, сколько позиций занято в стеке
char str1 = ' '; // здесь будут символы из строки

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Почему эту переменную нельзя объявить внутри цикла?

Название переменной странное. Во-первых, она типа char, а называет как будто это строка. Во-вторых, слишком общее, поэтому Вам и захотелось написать комментарий.

Comment thread src/bracketBalance.c Outdated
Comment on lines +13 to +14
char str2 = '(';
char str3 = ')';

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Научитесь объявлять константы. Хотя здесь они ни к чему. У Вас str2 и str3 встречаются ниже в коде по одному разу.

Comment thread src/bracketBalance.c Outdated

if (str1 == str2) // Ищем окрывающие скобки
{
stackForBrackets[count] = 2; // пусть 2 - это открывающая скобка

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

А если вдруг кто-то напишет в стек значение 42, что будет? Используйте максимально узкие типы. Здесь гораздо лучше бы подошел bool.

Comment thread src/bracketBalance.c Outdated
count -= 1;
// этими действиями мы убрали закрытые скобки, будто их и не было
} else {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Тут какая-то лишняя строка

Comment thread src/oneStringInAnother.c Outdated
{
bool flag = true; // Это значит, что все символы строк совпадают, но если хотя бы один символ будет отличаться, будем менять на 0 и выходить из цикла
for (int j = 0; j < lenForSmallerString; j++) {
if (listForBiggerString[i + j] != listForSmallerString[j]) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

А если i = lenForBiggerString-1, а j = lenForSmallerString? Какие данные мы будем читать?

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Я так понимаю, что те, которые просто дальше лежат в памяти и уже никак не относятся к моей программе... Исправлю!

Comment thread src/zerosInMassive.c Outdated
// пусть массив задан в программе
int listWithNumbers[] = { 0, 1, 3, 0, 6, 0, 7, 4, 6, 2, 0, 0 };
int countOfZeros = 0;
size_t lengthOfMassive = sizeof(listWithNumbers) / sizeof(int);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Massive --- это прилагательное! Array --- существительное.

Comment thread src/oneStringInAnother.c Outdated
size_t lenForBiggerString = sizeof(listForBiggerString) / sizeof(char);
size_t lenForSmallerString = sizeof(listForSmallerString) / sizeof(char) - 1; // так как последний символ нулевой

int countingOfEntry = 0; // счетчик вхождений

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

entryCounter тогда уж. Counting обычно герундий

Comment thread src/zerosInMassive.c Outdated
int main()
{
// пусть массив задан в программе
int listWithNumbers[] = { 0, 1, 3, 0, 6, 0, 7, 4, 6, 2, 0, 0 };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

А список --- не массив.

Comment thread src/zerosInMassive.c Outdated
{
// пусть массив задан в программе
int listWithNumbers[] = { 0, 1, 3, 0, 6, 0, 7, 4, 6, 2, 0, 0 };
int countOfZeros = 0;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Либо numberOfZeroes, либо zeroCounter

Comment thread src/bracketBalance.c Outdated
{
//специальный счетчик, "(" это +1 ")" это -1. Если скобочная посл-ть правильная, counter == 0
int counter = 0;
bool bracketsExist = false;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Эта переменная правда нужна? Неужели счётчика не хватает?

Comment thread src/bracketBalance.c Outdated
int counter = 0;
bool bracketsExist = false;

for (int i = 0; i < 100; i++) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Почему строго 100? Неужели если в строке будет 345 символов всю остальную логику нельзя будет использовать?

Comment thread src/zerosInMassive.c Outdated
int main()
{
// пусть массив задан в программе
int ArrayWithNumbers[] = { 0, 1, 3, 0, 6, 0, 7, 4, 6, 2, 0, 0 };

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Почти :( тут с маленькой буквы

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Эту задачу я зачту, а Вы поправите.

Comment thread src/oneStringInAnother.c Outdated

int entryCounter = 0;
// i - индекс эл-та с которого будем рассматривать большую строку
for (unsigned int i = 0; i < lenForBiggerString; i++) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
for (unsigned int i = 0; i < lenForBiggerString; i++) {
for (unsigned i = 0; i < lenForBiggerString; i++) {

по стайлгайду

Comment thread src/oneStringInAnother.c Outdated
for (unsigned int i = 0; i < lenForBiggerString; i++) {
bool flag = true;
for (unsigned int j = 0; j < lenForSmallerString; j++) {
if (i + j < lenForBiggerString) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Это можно сделать проще. Рассматривайте i не от 0 до lenForBiggerString - 1, а меньше, тогда будет меньше проблем с границами.

@yaprogrammer18-yanchi

yaprogrammer18-yanchi commented Oct 12, 2025

Copy link
Copy Markdown
Owner Author

Я изменила сообщение коммита и мне теперь выдает Merge branch 'lesson_3_branch' of github.com:yaprogrammer18-yanchi/C_Homework_ into lesson_3_branch... Можно я сделаю force push? :D

@WoWaster WoWaster left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Осталось отформатировать... :(

@WoWaster

Copy link
Copy Markdown
Collaborator

И в своих ветках делайте force-push сколько хотите.

@WoWaster WoWaster left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Я не понял, почему у Вас раздублировались файлы

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Зачтено.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Пусть уже будет.

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