Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Format problem in File

Status
Not open for further replies.

darr01

Programmer
Oct 24, 2001
28
MY
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
 
Hi,

Is there any way I can re-formatted the statement for e.g. as below so that the code is more easily read?
addEntry = toupper(getch()); /*only if you have <conio.h>*/
/* and <stdlib.h>*/
if(addEntry == 'Y')
{
/*note use of double quotes on each line.*/
fprintf(bookPtr, &quot;\nISBN No: %s\nBook Title: %s&quot;
&quot;\nAuthor: %s\nPublisher: %s&quot;
&quot;\nBook Type: %s\nPublication Month: %s&quot;
&quot;\nPublication Year: %s&quot;
&quot;\nPrice: %7.2f\n\n&quot;,
item.isbn,
item.bookTitle,
item.author,
item.publisher,
item.bookType,
item.month,
item.year,
bookPrice);
printf(&quot;Entry Saved!&quot;);
}

Hoping to get certified..in C programming.
 
bigtamscot, thanks for the code. I will give it a go. Hope you get your C certification soon!

Regards.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top