2013-05-06 45 views
-2

我有一个结构的名字排序结构的数组按字母顺序与具有空间

struct BookInfo 
{ 
    char title[50]; 
    int numAuthors; 
    char authors[50][50]; 
    int year; 
    int checkedout; 
}; 

我可以通过多年的排序,但我不能让它通过标题为我所有我的代码做的生命排序是打印出它们的顺序依次在文件中或我得到“在assingment不兼容的类型”错误的comented线

int j,i; 
    char temp; 
    for(i = 1; i < 14; i++) 
    { 
     j = i - 1; 
     while(j >= 0 && strcmp(library[j+1].title, library[j].title) < 0) 
     { 
      temp = library[j + 1]; /*errors*/ 
      library[j+1] = library[j]; 
      library[j] = temp; /*errors*/ 
      j--; 
     } 
     printf("n%s",library[j].title); 
    } 

的名字我在做什么错在这里?

+0

是什么类型库? – 2013-05-06 09:07:36

+0

struct BookInfo库[500]; – Tatan1 2013-05-06 09:12:42

回答

2

要排序BookInfo情况下,所以你temp变量应该是同一类型,而不是字符的:

int j,i; 
BookInfo temp; 
+0

我把结构放在BookInfo的前面,它可以工作,但仍然不会对图书 – Tatan1 2013-05-06 09:06:18

+0

@ Tatan1进行排序,这是另一回事。 “不排序”是什么意思?他们是否根本没有分类,或者只是部分分类,或者顺序不正确? – Andrei 2013-05-06 09:17:22

+0

没有排序......所有的名字只是按照他们正在读取的文件中的顺序打印 – Tatan1 2013-05-06 09:18:16