A
A
Abc Edc2014-09-12 11:28:37
Programming
Abc Edc, 2014-09-12 11:28:37

What's wrong with l buffersmall?

void read_database (Products**Ps) {
ifstream file;
Products*Inc=new Products;
Product S;
file.open("database.txt",ios::in);
if (!file) {
cout<<rus("База данных не доступна");
return;
}
long file_size;
file.seekg(0, ios::end);
file_size = file.tellg();
if (!file_size) {
cout<<rus("База данных пуста");
return;
}
file.close();
file.open("database.txt",ios::in);
file.read((char *) &S, sizeof(Product));
Inc->P.id=S.id;
strcpy_s(Inc->P.name, S.name);
strcpy_s(Inc->P.value, S.value);
Inc->P.price=S.price;
Inc->P.number=S.number;
strcpy_s(Inc->P.last_date, S.last_date);
Inc->next=NULL;
*Ps=Inc;
while(!file.eof()) {

Inc->next=new Products;
Inc=Inc->next;
Inc->P.id=S.id;
strcpy_s(Inc->P.name, S.name);
strcpy_s(Inc->P.value, S.value);
Inc->P.price=S.price;
Inc->P.number=S.number;
strcpy_s(Inc->P.last_date, S.last_date);
Inc->next=NULL;
}
file.close();
cout<<"-------------------------------"<<endl;
cout<<rus("Список товаров получен из файла")<<endl;
cout<<"-------------------------------"<<endl;
}

>
All functions are working, but when reading a file, it throws
File: f:\dd\vctools\crt_bld\self_x86\crt\ src\tcscpy_s.inl
Line: 30
Expression: (L "Buffer is too small" && 0)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2014-09-12
@EvgenijDv

You have too little buffer somewhere. Go under debugging and look at exactly where in your code this error occurs. Most likely it is in one of the strcpy_s.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question