Good day to all.
There is an initial array in which the user will enter a text, there is an array under the letter to be inserted into the word, and there is a result array in which there will be a word and the inserted letter in the word.
As the teacher told me that Word can be declared as a variable, not an array, but when the user enters a letter, the application simply crashes with the error window (it costs windows xp).
The most basic problem is that during transplantation the first letter of the source text disappears! In fact, it is important that after the user chooses a letter, the first letter in the source text disappears, he checked it himself.
The main thing for me is to understand why the letter disappeared. Thanks in advance for the answers and attention!
Below is a commented out loop, i.e. entering letters before position and after.
Do not pay attention to copying in a loop with 1, I checked that the symbol disappears, I know that you need to enter with 0. I solved the task myself, thank you all!
#include <conio.h> #include <string.h> #include <iostream> using namespace std; main(){ char text[10]; //наш исходный массив, предполагаемый текст - helloworld char word[1]; //(можно ли объявлять его не как массив?) наша буква char test[11]; //наш результирующий массив int position = 0, i; //позиция и счетчик printf("Enter text: "); gets(text); //вводим текст printf("%s", text); //проверяем, правильно ли введен (+правильно) printf("\nEnter word: "); fgets(word, 2, stdin); //вводим букву printf("%c", word[0]); //проверяем букву cout << "\nEnter position: "; cin >> position; cout << "\nPosition: " << position; position --; //мы считаем позицию с 0, пользователь с 1 for(i = 0; i < 11; i++){ //перенос букв из исходного массива в результирующий, переносит правильно, а первая буква пропадает test[i] = text[i]; printf("%c", test[i]); //отлавливаем, попадают ли буквы в результирующий массив getch(); //if(i == position) не работает //попытка вставить заданную букву на позицию результирующего массива, а после неё продолжить вставлять буквы из исходного массива //test[i] = 0; } /*for(i = 1; i < 6; i++){ printf("%c", test[i]); getch(); }*/ /*for(i = 0; i > position; i++){ test[i] = text[i]; printf("%c", test[i]); getch(); }*/ getch(); }