Skip to content

Conversation

@MinyazevR
Copy link
Owner

No description provided.

const int readBytes = fscanf(file, "%c", buffer);
if (readBytes < 0)
{
break;

Choose a reason for hiding this comment

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

Так буфер утечёт

return NULL;
}
}
const int readBytes = fscanf(file, "%c", buffer);

Choose a reason for hiding this comment

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

Да ну. Аж выделение памяти на куче под один символ, только для того, чтобы его тут же удалить. Во-первых, можно было выделять место под символ на стеке (char buffer = '\0') , во-вторых, можно было не выделять место вовсе: const int readBytes = fscanf(file, "%*c");

Comment on lines +32 to +33
fclose(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.

Можно было fseek(0);

int linesRead = 0;
while (!feof(file))
{
char* buffer = (char*)calloc(1, sizeof(char));

Choose a reason for hiding this comment

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

:(

*error = 2;
return NULL;
}
int linesRead = 0;

Choose a reason for hiding this comment

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

Это уже не linesRead, а количество символов

}
if (*buffer == ';')
{
while (*buffer != '\n' && *buffer != '\0' && linesRead <= counter)

Choose a reason for hiding this comment

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

Можно было просто сделать булевый флажок isComment, ставить его в true, если видим ";" и в false, если перевод строки. Хотя так тоже будет работать, просто сложнее.

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