Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Book* initBooksList(Book *p){
- char book_name_buffer[MAX_ROW];
- FILE *fp = fopen("books.txt","r");
- if (fp == NULL)
- exit(0);
- char str[MAX_ROW];
- int actual_len = 0;
- while (NULL != fgets(str, MAX_ROW, fp)){
- if (p == NULL){
- p == (Book*)malloc(sizeof(Book));
- for (int i = 0; i+1 != '$'; i++){
- book_name_buffer[i] = str[i];
- actual_len += 1;
- }
- strcpy(p->name,book_name_buffer);
- p->next == NULL;
- int cpy = 0;
- for (int i = actual_len+5; i != ' '; i++){
- cpy = cpy * 10 + int(str[i]);
- }
- p->copies = cpy;
- }
- else{
- Book* init = p;
- Book* buffer = NULL;
- Book* new_book = NULL;
- new_book == (Book*)malloc(sizeof(Book));
- for (int i = 0; i + 1 != '$'; i++){
- book_name_buffer[i] = str[i];
- actual_len += 1;
- }
- strcpy(new_book->name, book_name_buffer);
- int cpy = 0;
- for (int i = actual_len + 5; i != ' '; i++){
- cpy = cpy * 10 + int(str[i]);
- }
- new_book->copies = cpy;
- while (p!= NULL && strcmp(new_book->name, p->name) < 0){
- buffer = p;
- p = p->next;
- }
- if (p == NULL){
- buffer->next = new_book;
- new_book->next = NULL;
- p = init;
- }
- else{
- buffer->next = new_book;
- new_book->next = p;
- p = init;
- }
- }
- }
- fclose(fp);
- return p;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement