Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 777015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T19:32:25+00:00 2026-05-14T19:32:25+00:00

I’m currently working on an assignment and this have had me stuck for hours.

  • 0

I’m currently working on an assignment and this have had me stuck for hours. Can someone please help me point out why this isn’t working for me?


struct book
{
  char title[25];
  char author[50];
  char subject[20];
  int callNumber;
  char publisher[250];
  char publishDate[11];
  char location[20];
  char status[11];
  char type[12];
  int circulationPeriod;
  int costOfBook;
}; 

void PrintBookList(struct book **bookList)
{
  int i;
  for(i = 0; i < sizeof(bookList); i++)
  {
    struct book newBook = *bookList[i];
    printf("%s;%s;%s;%d;%s;%s;%s;%s;%s;%d;%d\n",newBook.title, newBook.author, newBook.subject, 
        newBook.callNumber,newBook.publisher, newBook.publishDate, newBook.location, newBook.status, 
        newBook.type,newBook.circulationPeriod, newBook.costOfBook);

  }
}

void GetBookList(struct book** bookList)
{
  FILE* file = fopen("book.txt", "r");
  struct book newBook[1024];
  int i = 0;

  while(fscanf(file, "%s;%s;%s;%d;%s;%s;%s;%s;%s;%d;%d",
        &newBook[i].title, &newBook[i].author, &newBook[i].subject, 
        &newBook[i].callNumber,&newBook[i].publisher, &newBook[i].publishDate, 
        &newBook[i].location, &newBook[i].status,
        &newBook[i].type,&newBook[i].circulationPeriod, &newBook[i].costOfBook) != EOF)
  {
    bookList[i] = &newBook[i];
    i++;
  }

  /*while(fscanf(file, "%s;%s;%s;%d;%s;%s;%s;%s;%s;%d;%d",
    &bookList[i].title, &bookList[i].author, &bookList[i].subject,
    &bookList[i].callNumber, &bookList[i].publisher, &bookList[i].publishDate,
    &bookList[i].location, &bookList[i].status, &bookList[i].type,
    &bookList[i].circulationPeriod, &bookList[i].costOfBook) != EOF)
  {
    i++;
  }*/

  PrintBookList(bookList);

  fclose(file);
}

int main()
{
  struct book *bookList[1024];
  GetBookList(bookList);
}

I get no errors or warnings on compile

it should print the content of the file, just like it is in the file.
Like this:

OperatingSystems Internals and Design principles;William.S;IT;741012759;Upper Saddle River;2009;QA7676063;Available;circulation;3;11200
Communication skills handbook;Summers.J;Accounting;771239216;Milton;2010;BF637C451;Available;circulation;3;7900
Business marketing management:B2B;Hutt.D;Management;741912319;Mason;2010;HF5415131;Available;circulation;3;1053
Patient education rehabilitation;Dreeben.O;Education;745121511;Sudbury;2010;CF5671A98;Available;reference;0;6895  
Tomorrow's technology and you;Beekman.G;Science;764102174;Upper Saddle River;2009;QA76B41;Out;reserved;1;7825  
Property & security: selected essay;Cathy.S;Law;750131231;Rozelle;2010;D4A3C56;Available;reference;0;20075  
Introducing communication theory;Richard.W;IT;714789013;McGraw-Hill;2010;Q360W47;Available;circulation;3;12150  
Maths for computing and information technology;Giannasi.F;Mathematics;729890537;Longman;Scientific;1995;QA769M35G;Available;reference;0;13500  
Labor economics;George.J;Economics;715784761;McGraw-Hill;2010;HD4901B67;Available;circulation;3;7585  
Human physiology:from cells to systems;Sherwood.L;Physiology;707558936;Cengage Learning;2010;QP345S32;Out;circulation;3;11135  
bobs;thomas;IT;701000000;UC;1006;QA7548;Available;Circulation;7;5050

but when I run it, it outputs this:

OperatingSystems;;;0;;;;;;0;0  
Internals;;;0;;;;;;0;0  
and;;;0;;;;;;0;0  
Design;;;0;;;;;;0;0  
principles;William.S;IT;741012759;Upper;41012759;Upper;;0;;;;;;0;0  
Saddle;;;0;;;;;;0;0  
River;2009;QA7676063;Available;circulation;3;11200;lable;circulation;3;11200;;0;;;;;;0;0  
Communication;;;0;;;;;;0;0  

Thanks in advance, you’re a life saver

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T19:32:26+00:00Added an answer on May 14, 2026 at 7:32 pm

    I think your problem is that your fields contain spaces. fscanf will stop scanning a string (%s) when it sees a white space character. You need to change your %s format specifiers to allow spaces to be included. You can either just exclude your delimiter, e.g. %[^;] or specify what characters to include, e.g. %[ a-zA-Z0-9-] (I think I’d probably go for the first option).

    % man fscanf

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.