c - How to write a blank line to a text file? -


i'm writing program keep inventory of books, reads list of books text file , writes additional books file. got add new books file, have blank line between each book entry. how can that? other info might useful or needed: i'm using structure hold title, author, , isbn in character strings.

here's part collects new data: it's put linked list.

puts("enter first book title."); while(fgets(input, 80, stdin) != null && input[0] != '\n') { current = (struct book *)malloc(sizeof(struct book)); if(head == null)    head = current; else    prev->next = current; current->next = null;  strcpy(current->title, input); puts("enter author."); fgets(current->author, 80, stdin); puts("enter isbn."); fgets(current->isbn, 80, stdin);  puts("enter next book title (empty line quit)"); prev = current; } 

here's part writes file:

input_file = fopen("library.txt", "w");  printf("printing list file...\n"); while(current != null) {   fprintf(input_file,"%s%s%s", current->title, current->author, current->isbn);   //fputs(newline, input_file);     } 

that's relevant part. commented part tried, put newlines over, messing data nicely formatted. here's little example of how text file should (ignore coloring):

title 1 last, first 000000 (isbn)  title 2 last, first 111111  etc. 

when add book , program writes file, adds (left out isbn clarity):

... title 2 last, first first added book last, first second added title last, first etc. 

how can empty line in between each book entry?

why not insert newline-character (\n) in line?

fprintf(input_file,"%s%s%s", current->title, current->author, current->isbn); 

->

fprintf(input_file,"%s%s%s\n", current->title, current->author, current->isbn); 

fyi, if add more \n more empty lines.


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -