C语言图书管理系统问题困难

img

img

如图,该怎么改printf函数可以实现长短字符左对齐输出呢?

fprintf(fp,"%d\t%s\t%.2f\t%s\t\t%s\t%s\t%d\n"
改成
fprintf(fp,"%6d\t%20s\t%.2f\t%20s\t\t%20s\t%20s\t%5d\n"

可修改数字对齐,望采纳!

代码
void printBookList(struct node* head)
{
struct node* p=head->next;
printf("图书编号\t书名\t\t价格\t作者\t\t出版社\t\t类别\t借阅状态\n");
BOOK *b;
while(p!=NULL)
{
b = &(p->book);
printf("%d\t\t%s\t%.2f\t%s\t\t%s\t%s\t%s\n", b->IBSN, b->name, b->price,
b->author,b->pub,b->classify, (b->state==0 ? "0-未借出":"1-已借出")) ;
p = p->next;
}
}

void saveBookListToFile(struct node* head)
{
if(head != NULL)
{
struct node p=head->next;
FILE
fp=fopen(BOOK_FILE, "w+");
fprintf(fp,"图书编号\t书名\t\t价格\t作者\t\t出版社\t\t类别\t借阅状态\n");
if(fp!=NULL)
{
while(p!=NULL)
{

    fprintf(fp,"%d\t%s\t%.2f\t%s\t\t%s\t%s\t%d\n", (p->book).IBSN,\
      (p->book).name, (p->book).price, (p->book).author, \
 (p->book).pub,(p->book).classify,(p->book).state);
    p=p->next;
  }
  fclose(fp);
  
}else 
{
  
  printf("打开book.txt文件失败,请检查!\n");
}  

}
}