Hi, guys. I need to save user input in a preformatted format into a file (e.g. database.txt).
This means that when the file is viewed by using a text editor, it should be formatted as I wanted it. See e.g.
below.
ISBN No: 3-23433-443-8
Book Name: My Book
Author: Myself
Publisher: Web Publishing
Published Month: Dec
Published Year: 2001
Price: 23.99
I can do the above using this code below IF and ONLY IF I don't press the 'Enter' key to move the portion of
the statement to the next line (as the code is too long), else the compiler will give a 'newline constant error'.
if(addEntry == 'y' || addEntry == 'Y')
{
fprintf(bookPtr, "\nISBN No: %s\nBook Title: %s\nAuthor: publisher: %s\nBook Type:
%s\nPublication Month: %s\nPublication Year: %s\nPrice: 7.2f\n\n",item.isbn, item.bookTitle, item.author, item.publisher, item.bookType, item.month, item.year,bookPrice);
printf("Entry Saved!"
}
Is there any way I can re-formatted the statement for e.g. as below so that the code is more easily read?
if(addEntry == 'y' || addEntry == 'Y')
{
fprintf(bookPtr,
"\nISBN No: %s
\nBook Title: %s
\nAuthor: %s
\nPublisher: %s
\nBook Type: %s
\nPublication Month: %s
\nPublication Year: %s
\nPrice: %7.2f\n\n",
item.isbn,
item.bookTitle,
item.author,
item.publisher,
item.bookType,
item.month,
item.year,
bookPrice);
printf("Entry Saved!"
}
Thanks,
Darryl HB
This means that when the file is viewed by using a text editor, it should be formatted as I wanted it. See e.g.
below.
ISBN No: 3-23433-443-8
Book Name: My Book
Author: Myself
Publisher: Web Publishing
Published Month: Dec
Published Year: 2001
Price: 23.99
I can do the above using this code below IF and ONLY IF I don't press the 'Enter' key to move the portion of
the statement to the next line (as the code is too long), else the compiler will give a 'newline constant error'.
if(addEntry == 'y' || addEntry == 'Y')
{
fprintf(bookPtr, "\nISBN No: %s\nBook Title: %s\nAuthor: publisher: %s\nBook Type:
%s\nPublication Month: %s\nPublication Year: %s\nPrice: 7.2f\n\n",item.isbn, item.bookTitle, item.author, item.publisher, item.bookType, item.month, item.year,bookPrice);
printf("Entry Saved!"
}
Is there any way I can re-formatted the statement for e.g. as below so that the code is more easily read?
if(addEntry == 'y' || addEntry == 'Y')
{
fprintf(bookPtr,
"\nISBN No: %s
\nBook Title: %s
\nAuthor: %s
\nPublisher: %s
\nBook Type: %s
\nPublication Month: %s
\nPublication Year: %s
\nPrice: %7.2f\n\n",
item.isbn,
item.bookTitle,
item.author,
item.publisher,
item.bookType,
item.month,
item.year,
bookPrice);
printf("Entry Saved!"
}
Thanks,
Darryl HB