I'm still new to the lists in C and I have a big problem ... first I would like to put your code Items in the list show:
Zero input_books_info (int number_of_books, book * on) {int i; For (i = 0; i & lt; number_of_books; i ++) {while (current-> next! = Null) current = current-> next; Current-gt; Next = (book *) malloc (sizeof (book)); Printf_s ("% d book list number:", i + 1); Scanf_s ("% s", and; current-> next-> catalog_number, 20); Printf_s ("% d book title:", i + 1); Scanf_s ("% s", current- gt; next-> gt; title, 80); Printf_s ("% d book author:", i + 1); Scanf_s ("% s", current-> next-> author, 40); Printf_s ("% d book publisher:", I + 1); Scanf_s ("% s", current-> gt; next->, publisher, 80); Printf_s ("price of% d book:", i + 1); Scanf_s ("% f", and; current-> next-> value, 5); Printf_s ("% d published in the book year:", i + 1); Scanf_s ("% d", and; current-> next-> year_published, 5); Current-> Next-> gt; Next = null; Printf_s ("\ n \ n"); }}
And this is my main function:
zero main (zero) {int number_of_books, t = 1; Char book_catalog_number [STRMAX]; Four book [title] [STRMX]; Char BookIther [STRMAX]; Four reading_file [STRMAX]; Char saving_file [STRMAX]; First = maulock (bookfold); First-> gt; Next = null; / * Printf_s ("Enter File Name:"); Gets (saving_file); First-> gt; Next = book_open (before, saving_file); * / While (t) {four m; Printf_s ("1. Input \ n0. Exit \ n \ n"); Printf_s ("Choose Operation:"); Me = mill (); Switch (m) {case '1': printf_s ("books \ n input number:"); Scanf_s ("% d", and number_of_books); Input_books_info (number_of_books, before); Printf_s ("\ n"); break; Default: printf_s ("\ n no entry was found! \ N \ n \ n \ n \ n"); break; }}}
And the problem is the printing function for the last time:
zero print_books_info (book * current) {while (current-> next! = Null And current! = Null) {printf_s ("% s,", current-> gt; next-> catalog_number); Printf_s ("% s,", current-> author); Printf_s ("% s,", current->; next-> title); Printf_s ("% s,", current->; next-> author); Printf_s ("% s,", current->; Next-> Publisher); Printf_s ("% .2f,", current->; next-> values); Printf_s ("% d", current-> gt; next-> year_published); Printf_s ("\ n \ n"); Current = current-> next; }}
And my problem is that, when I run the app, the program is running well but when I start the app, the program is only collecting the first input of the second data And the third is lost ... can you help me figure it out ... ???
I suspect it is scanf_s which is reading more than the intent of the field, instead of buffering the whole line Use Single ScanFus to read in, then use sscanf_s to parse buffer.
Apart from this, since you do not show the announcement of the book, we are shooting all of a little blindly, but the elements of the book are properly dimensional? If not, the element will be overwritten while reading. The book should look like this:
class book {book * next; Four list_number [20]; // At least 20 characters are four titles [80]; Four authors [40]; Four publishers [80]; Double price; Int year_published; };
Comments
Post a Comment