{"id":79161,"date":"2021-12-02T22:54:02","date_gmt":"2021-12-02T22:54:02","guid":{"rendered":"https:\/\/papersspot.com\/blog\/2021\/12\/02\/include-include-include-include-define-title_len-100-define-3\/"},"modified":"2021-12-02T22:54:02","modified_gmt":"2021-12-02T22:54:02","slug":"include-include-include-include-define-title_len-100-define-3","status":"publish","type":"post","link":"https:\/\/papersspot.com\/blog\/2021\/12\/02\/include-include-include-include-define-title_len-100-define-3\/","title":{"rendered":"#include  #include  #include  #include  #define TITLE_LEN 100 #define"},"content":{"rendered":"<p>#include <\/p>\n<p> #include <\/p>\n<p> #include <\/p>\n<p> #include <\/p>\n<p> #define TITLE_LEN 100<\/p>\n<p> #define NAME_LEN 30<\/p>\n<p> #define ROOM_LEN 20<\/p>\n<p> \/\/ SCOURCE FILE FOR THE OTHER FUNCTIONS \/\/<\/p>\n<p> #include &#8220;book.h&#8221;<\/p>\n<p> #include &#8220;readline.h&#8221;<\/p>\n<p> struct book *add_to_end(struct book *list){<\/p>\n<p> \/\/add code<\/p>\n<p> struct book *prev_book = NULL, *end = list;<\/p>\n<p> struct book *new_book = NULL;<\/p>\n<p> new_book = malloc(1 * sizeof(struct book));<\/p>\n<p> if (new_book == NULL) { \/\/ make sure that here is still a memory in allocate<\/p>\n<p> printf(&#8220;Error: malloc failed in add_to_list\\n&#8221;);<\/p>\n<p> exit(EXIT_FAILURE);<\/p>\n<p> }<\/p>\n<p> printf(&#8220;Enter the Book&#8217;s title: &#8220;); \/\/ Ask the user to enter the title,<\/p>\n<p> read_line(new_book-&gt;title,TITLE_LEN); \/\/ read the input<\/p>\n<p> printf(&#8220;Enter the Author&#8217;s first name: &#8220;); \/\/ Ask the user to enter the author first name<\/p>\n<p> read_line(new_book-&gt;first,NAME_LEN); \/\/ read the input<\/p>\n<p> printf(&#8220;Enter the Author&#8217;s last name: &#8220;); \/\/ Ask the user to enter the author last name<\/p>\n<p> read_line(new_book-&gt;last,NAME_LEN); \/\/ read the input<\/p>\n<p> printf(&#8220;Enter Classroom: &#8220;); \/\/ Ask the user to enter classroom<\/p>\n<p> read_line(new_book-&gt;classroom,ROOM_LEN); \/\/ read the input<\/p>\n<p> new_book-&gt;next = NULL; \/\/ go for the next book<\/p>\n<p> \/\/ add the book yo the list<\/p>\n<p> if (!list) {<\/p>\n<p> \/\/ if the list is empty<\/p>\n<p> printf(&#8220;Enter the price of the book: &#8220;);<\/p>\n<p> scanf(&#8220;%lf&#8221;, &amp;new_book-&gt;price);<\/p>\n<p> return new_book;<\/p>\n<p> }<\/p>\n<p> \/\/ if the list is not empty<\/p>\n<p> while (end != NULL) { \/\/ cheack is the book is already there by comparing it<\/p>\n<p> if (!strncmp(new_book-&gt;title, end-&gt;title, TITLE_LEN + 1) &amp;&amp;<\/p>\n<p> !strncmp(new_book-&gt;first, end-&gt;first, NAME_LEN + 1) &amp;&amp;<\/p>\n<p> !strncmp(new_book-&gt;first, end-&gt;first, NAME_LEN + 1)) {<\/p>\n<p> printf(&#8220;Book is already exists\\n&#8221;); \/\/ if there is a book with the same title, author, classrom<\/p>\n<p> free(new_book);<\/p>\n<p> return list;<\/p>\n<p> } else { \/\/ if nott we add it to the end<\/p>\n<p> prev_book = end;<\/p>\n<p> end = end-&gt;next;<\/p>\n<p> }<\/p>\n<p> }<\/p>\n<p> \/\/ if there is no book does not exists<\/p>\n<p> printf(&#8220;Enter the price of the book: &#8220;); \/\/ ask the user to enter the price for it<\/p>\n<p> scanf(&#8220;%lf&#8221;, &amp;new_book-&gt;price);<\/p>\n<p> prev_book-&gt;next = new_book; \/\/ the new book go next to the end of the linked list<\/p>\n<p> return list; \/\/ return to the list<\/p>\n<p> }<\/p>\n<p> void search(struct book *list)<\/p>\n<p> {<\/p>\n<p> \/\/ add code<\/p>\n<p> char search_title[TITLE_LEN+1]; \/\/ string for the search input<\/p>\n<p> struct book *p;<\/p>\n<p> printf(&#8220;\\nEnter title book: &#8220;);<\/p>\n<p> read_line(search_title, TITLE_LEN); \/\/ read the input<\/p>\n<p> \/* a for loop that goes over all the list and search for the same title name<\/p>\n<p> and stops when p == NULL *\/<\/p>\n<p> for (p = list; p != NULL; p = p-&gt;next)<\/p>\n<p> \/\/ if statent to compare the input title with the title in the lists<\/p>\n<p> if (!strncmp(search_title, p-&gt;title, TITLE_LEN + 1)){<\/p>\n<p> \/\/ if found it print the book name<\/p>\n<p> printf(&#8220;%-18s %s %-7s %.2f %s\\n&#8221;, p-&gt;title, p-&gt;first, p-&gt;last, p-&gt;price, p-&gt;classroom);<\/p>\n<p> }<\/p>\n<p> else<\/p>\n<p> \/\/ if not found print a message that didnt found<\/p>\n<p> printf(&#8220;book dont found\\n&#8221;);<\/p>\n<p> return; \/\/ return empty<\/p>\n<p> }<\/p>\n<p> void print_list(struct book *list){<\/p>\n<p> \/\/add code<\/p>\n<p> \/\/ print all lists<\/p>\n<p> printf(&#8220;Book Title Auther Name price Classroom\\n&#8221;);<\/p>\n<p> struct book *p;<\/p>\n<p> \/\/ a for loop that make sure it goes over all the books and stop in NULL<\/p>\n<p> for(p= list; p!=NULL; p = p-&gt;next)<\/p>\n<p> \/\/ print: title, authors first and last name, price, and classroom<\/p>\n<p> printf(&#8220;%-18s %s %-7s %.2f %s\\n&#8221;, p-&gt;title, p-&gt;first, p-&gt;last, p-&gt;price, p-&gt;classroom);<\/p>\n<p> printf(&#8220;\\n&#8221;);<\/p>\n<p> }<\/p>\n<p> void clear_list(struct book *list)<\/p>\n<p> {<\/p>\n<p> \/\/add code<\/p>\n<p> struct book *p;<\/p>\n<p> \/\/ a while loop that free the list and go to the next till its empty<\/p>\n<p> while(list != NULL)<\/p>\n<p> {<\/p>\n<p> p = list;<\/p>\n<p> list = list-&gt;next;<\/p>\n<p> if( p!= NULL)<\/p>\n<p> free(p);<\/p>\n<p> }<\/p>\n<p> }<\/p>\n","protected":false},"excerpt":{"rendered":"<p>#include #include #include #include #define TITLE_LEN 100 #define NAME_LEN 30 #define ROOM_LEN 20 \/\/ SCOURCE FILE FOR THE OTHER FUNCTIONS \/\/ #include &#8220;book.h&#8221; #include &#8220;readline.h&#8221; struct book *add_to_end(struct book *list){ \/\/add code struct book *prev_book = NULL, *end = list; struct book *new_book = NULL; new_book = malloc(1 * sizeof(struct book)); if (new_book == NULL) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10],"class_list":["post-79161","post","type-post","status-publish","format-standard","hentry","category-research-paper-writing","tag-writing"],"_links":{"self":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/79161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/comments?post=79161"}],"version-history":[{"count":0,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/79161\/revisions"}],"wp:attachment":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/media?parent=79161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/categories?post=79161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/tags?post=79161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}