Я делаю программу для хранения коллекции книг библиотеки. Один из вариантов - добавить новую книгу в массив структур.c-строка сохраняется в конце другой c-строки
Вот код
do
{
repeat = 0;
cout << "Enter the book's title: ";
cin.getline(tempTitle, (TITLE_SIZE) * 2);
for (int i = 0; i < bookNumber; i++)
{
if (strcmp(tempTitle, bookArray[i].title) == 0)
{
cout << "That title has already been entered, please enter a new book\n";
repeat = 1;
}
}
if (strlen(tempTitle) < 1 || strlen(tempTitle) > TITLE_SIZE)
{
cout << "The Book's title must be between 1 and 50 characters long\n";
repeat = 1;
}
} while (repeat == 1);
strncpy(bookArray[bookNumber].title, tempTitle, TITLE_SIZE);
file << bookArray[bookNumber].title << "\n";
do
{
repeat = 0;
cout << "Enter the book's ISBN number: ";
cin.getline(tempIsbn, (ISBN_SIZE) * 2);
if (strlen(tempIsbn) != ISBN_SIZE)
{
cout << "The Book's title must be 13 digits long\n";
repeat = 1;
}
} while (repeat == 1);
strncpy(bookArray[bookNumber].isbn, tempIsbn, ISBN_SIZE);
Вот мой вход
Enter the book's title: new book title
Enter the book's ISBN number: 0000000000000
Enter the book's author: Person
Is the book currently in stock (y/n)? y
Вот что она сохраняется как
Title : new book title
ISBN #: 0000000000000Person
Author: Person
Status: Available
Почему он сохраняет c-строку автора до конца c-строки isbn?