Skip to content

Glagolev ruslan homework3#29

Open
RuslanGlagolev wants to merge 2 commits intomasterfrom
glagolev_ruslan_homework3
Open

Glagolev ruslan homework3#29
RuslanGlagolev wants to merge 2 commits intomasterfrom
glagolev_ruslan_homework3

Conversation

@RuslanGlagolev
Copy link
Collaborator

No description provided.


int main() {
char array[200];
char array_reverse[200];
Copy link
Owner

Choose a reason for hiding this comment

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

Литерал 200 сделайте константой

int main() {
char array[200];
char array_reverse[200];
int index_array_reverse = 0;
Copy link
Owner

Choose a reason for hiding this comment

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

сделайте эту переменную как тип size_t
так как у вас будут варнинги при компиляции

warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (index_array_reverse < index_array) {

это все из за того что перменные index_array_reverse и index_array разных типов
ну и последнее) а зачем вы тут обьявляете эту переменную? почему бы ее не обьявить перед самим while

while (array[index_array] != '\0') {
index_array++;
}
int Index_array = index_array;
Copy link
Owner

Choose a reason for hiding this comment

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

тут у вас также трабла, вы присваиваете тип с большим размером типу с меншим размером.
У вас переменная Index_array должна быть как минимум такого же типа как и переменная index_array

while (index_array_reverse < index_array) {
Index_array--;
array_reverse[index_array_reverse] = array[Index_array];
index_array_reverse++;
Copy link
Owner

Choose a reason for hiding this comment

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

можно было бы и так написать

array_reverse[index_array_reverse++] = array[Index_array--];

Т.е. у вас бы постинкремент и постдекремнт вернул бы старое значение переменных которые бы пошли как индекс массива, а сами переменные индекса увеличились/уменшились бы на 1

std::cout << "Your inverted word-";
for (int i = 0; i < index_array; ++i) {
std::cout << array_reverse[i];
}
Copy link
Owner

Choose a reason for hiding this comment

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

у массивов символов есть определенное приимущество над массивом других типов.
А приимущество в том что массив можно выводить сразу в cout, т.е. не нужно посимвольно выводить
Можно написать так

std::cout << array_reverse << std::endl;

Но это работает только для массива символов, например для массивов int такое работать не будет

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