爱问知识人 爱问教育 医院库

C语言程序自动跳出问题 急!!!!!求解

首页

C语言程序自动跳出问题 急!!!!!求解

求高手!! 
                                     

#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>

struct books_list
{
   
   char author[20];              /*作者名*/
   char bookname[20];            /*书名*/ 
   char publisher[20];          /*出版单位*/
   char pbtime[15];              /*出版时间*/
   char loginnum[10];            /*登陆号*/
   float  price;                 /*价格*/
   char classfy[10];             /*分类号*/
   struct books_list * next;  /*链表的指针域*/
};
      
struct books_list * Create_Books_Doc();     /*新建链表*/
void InsertDoc(struct books_list * head); /*插入*/
void DeleteDoc(struct books_list * head );/*删除*/
void Print_Book_Doc(struct books_list * head);/*浏览*/
void search_book(struct books_list * head); /*查询*/
void info_change(struct books_list * head);/*修改*/
void save(struct books_list * head);/*保存数据至文件*/

/*新建链表头节点*/
struct books_list * Create_Books_Doc()
{
 struct books_list * head;
 head=(struct books_list *)malloc(sizeof(struct books_list)); /*分配头节点空间*/
 head->next=NULL;  /*头节点指针域初始化,定为空*/
 return head;
}
  
/*保存数据至文件*/
void save(struct books_list * head)
{
 struct books_list *p;
 FILE *fp;
 p=head;
 fp=fopen("data.txt","w+"); /*以写方式新建并打开 data.txt文件*/
 fprintf(fp,"...............................................................................\n"); /*向文件输出表格*/
 fprintf(fp,"   CAS RN    book name     author dan wei      data    sortnum  price  \n");
   getch();

 /*指针从头节点开始移动,遍历至尾结点,依次输出图书信息*/
 while(p->next!= NULL)
 {
  p=p->next;
  fprintf(fp,"%-6.6s  %-10.10s  %-10.10s  %-10.10s  %-12.12s  %-6.6s  %.2f     \n",p->loginnum,p->bookname,p->author,p->publisher,p->pbtime,p->classfy,p->price);
 }

 fclose(fp);
 printf("                  save data.txt 文件\n");
}

/*插入*/
void InsertDoc(struct books_list *head)
{
 /*定义结构体指针变量 s指向开辟的新结点首地址 p为中间变量*/
 struct books_list *s, *p;
 char flag='Y'; /*定义flag,方便用户选择重复输入*/
 p=head;
 /*遍历到尾结点,p指向尾结点*/
 while(p->next!= NULL)
    {
  p=p->next;
 }   
 /*开辟新空间,存入数据,添加进链表*/
 while(flag=='Y'||flag=='y')
 {
  s=(struct books_list *)malloc(sizeof(struct books_list));
  printf("\n                 Please input books landed number:");
  fflush(stdin);
  scanf("%s",s->loginnum);
  printf("\n                 Please enter the book name:");
  fflush(stdin);
  scanf("%s",s->bookname);
  printf("\n                 Please input book author's name:");
  fflush(stdin);
  scanf("%s",s->author);
  printf("\n                 Please input book publishing house:");
  fflush(stdin);
  scanf("%s",s->publisher);
  printf("\n                 Please enter publishing time:");
  fflush(stdin);
  scanf("%s",s->pbtime);
  printf("\n                 Please input book classification number:");
  fflush(stdin);
  scanf("%s",s->classfy);
  printf("\n                 Please input book prices:");
  fflush(stdin);
  scanf("%f",&s->price);
  printf("\n");
  getch();
  p->next=s;  /*将新增加的节点添加进链表*/
        p=s;  /*p指向尾节点,向后移*/
  s->next=NULL;
  getch();
  printf("......Add success!");
  getch();
  printf("\n   Continue to add?(Y/N):");

提交回答

全部答案

    2011-04-20 03:38:41
  • 大概你的原文太长。我们只看到前一部分。
    问题在哪里?
    

    2***

    2011-04-20 03:38:41

类似问题

换一换
  • 软件 相关知识

  • 电脑网络技术
  • 电脑网络

相关推荐

正在加载...
最新资料 推荐信息 热门专题 热点推荐
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200

热点检索

  • 1-20
  • 21-40
  • 41-60
  • 61-80
  • 81-100
  • 101-120
  • 121-140
  • 141-160
  • 161-180
  • 181-200
返回
顶部
帮助 意见
反馈

确定举报此问题

举报原因(必选):