Answer the question
In order to leave comments, you need to log in
Database in SI. Why doesn't it compile further?
After entering the data, it does not proceed to enter the price and quantity.
Listing:
#include <stdio.h>
#include <stdlib.h>
#include<windows.h>
#include<conio.h>
#pragma warning(disable : 4996)
#define _CRT_SECURE_NO_WARNINGS
int main()
{
typedef struct
{
char book_name[40];
float price;
int qty;
}book;
FILE* fptr;
book b;
char choice, filename[13];
int size = sizeof(book);
system("cls");
printf_s("Enter the name of file for data storoge and retrieval:");
gets_s(filename);
fptr = fopen(filename, "a+");
if (!fptr)
printf_s("\n Cant't open source file for writting\n ");
else {
printf_s("\n Do you wish to store a book record (y/n)?\n");
scanf_s("%c", &choice);
while (choice == 'y' || choice == 'Y')
{
fflush(stdin);
printf_s("\nEnter the book name\n");
scanf_s("%[^/n]s", b.book_name);
printf_s("Enter the price and quantity\n"); // Не появляется далее это.
scanf_s("%f%d", &b.price, &b.qty);
fwrite(&b, size, 1, fptr);
fflush(stdin);
printf_s("\n Do you wish to store another book record (y/n)?\n");
scanf_s("%c", &choice);
}
fclose(fptr);
system("cls");
fptr = fopen(filename, "r+");
if (!fptr)
printf_s("\n Cant't open source file for reading\n ");
else
{
printf_s("File %s contents are shown under field names\n\n", filename);
printf_s("\n\t\t\tBook Title\t\t Price\t Quantity\n\n");
while (fread(&b,size, 1, fptr) == 1)
printf_s("%40s\t%8.2f&8d\n", b.book_name, b.price, b.qty);
fclose(fptr);
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question