The qsort is at 00000159
Code:
00000010 #include "index.h"
00000011 #include "index_options.h"
00000012 #include "index_utility.h"
00000013
00000014 /****************************************************************************
****************************************************************************/
00000019 void readRestOfLine()
00000020 {
00000021 int c;
00000022
00000023 /* Read until the end of the line or end-of-file. */
00000024 while ((c = fgetc(stdin)) != '\n' && c != EOF)
00000025 ;
00000026
00000027 /* Clear the error and end-of-file flags. */
00000028 clearerr(stdin);
00000029 }
00000030
00000031
00000032 /****************************************************************************
00000033 * Initialises the index to a safe empty state.
00000034 ****************************************************************************/
00000035 void systemInit(IndexType* index)
00000036 {
00000037 index->uniqueWords=0;
00000038
00000039 }
00000040
00000041
00000042 /****************************************************************************
00000043 * Loads all data into the index.
00000044 ****************************************************************************/
00000045 int loadData(IndexType* index, char* trecFile)
00000046 {
00000047 WordType * curr, * head;
00000048
00000049 WordType *root;
00000050 index->headWord=root;
00000051 WordType *conductor;
00000052
00000053 root = (WordType *)malloc(sizeof(WordType));
00000054 root->nextWord=0;
00000055 root->word=NULL;
00000056
00000057 index->headWord=root;
00000058
00000059 conductor=root;
00000060
00000061 if ( conductor != 0 ) {
00000062 while ( conductor->nextWord != 0)
00000063 conductor = conductor->nextWord;
00000064 }
00000065
00000066
00000067 char wordvar[MAX_SIZE];
00000068 int j=0;
00000069 int k=0;
00000070 char c;
00000071 int tag=0;
00000072 FILE *fp;
00000073 printf("%s\n",trecFile);
00000074 fp = fopen(trecFile, "r");
00000075 if ( fp == NULL)
00000076 {
00000077 fprintf(stderr, "\nUnable to open file %s\n", trecFile);
00000078 system("PAUSE");
00000079 return EXIT_SUCCESS;
00000080 }
00000081 else
00000082 {
00000083 printf("\nFile %s open\n",trecFile);
00000084 while(( c = getc(fp)) != EOF)
00000085 {
00000086 if(c=='<'){
00000087 tag=1;
00000088 }
00000089 if (1 !=tag){
00000090 if(tolower(c)>96 && tolower(c) <123){
00000091 /*printf("%c",tolower(c));*/
00000092 wordvar[j]=tolower(c);
00000093 j++;
00000094 }
00000095
00000096 if (c==' '){
00000097 wordvar[j+1]='\0';
00000098 curr = (WordType *)malloc(sizeof(WordType));
00000099 /*curr->count++;*/
00000100 curr->word = (char*) malloc ( MAX_SIZE*sizeof( char ) );
00000101 if (wordvar[0]>96 && wordvar[0]<123){
00000102 strncpy( curr->word, wordvar, MAX_SIZE-1 );
00000103 index->totalWords++;
00000104 conductor->nextWord = (WordType *)malloc(sizeof(WordType));
00000105 conductor = conductor->nextWord;
00000106 conductor->nextWord = 0;
00000107 conductor->word = strncpy( curr->word, wordvar, MAX_SIZE-1 );
00000108 curr->nextWord = head;
00000109 }
00000110 for(j=0;j<=MAX_SIZE-1;j++) {
00000111 wordvar[j]=NULL;
00000112 }
00000113 j=0;
00000114 }
00000115
00000116 }
00000117 if(c=='>'){
00000118 tag=0;
00000119 }
00000120 }
00000121
00000122 }
00000123
00000124 fclose(fp);/* closes stream fp */
00000125 /*finalise linked list*/
00000126 conductor->nextWord = (WordType *)malloc(sizeof(WordType));
00000127 conductor = conductor->nextWord;
00000128 conductor->nextWord = 0;
00000129 conductor->word = NULL;
00000130
00000131
00000132
00000133
00000134 printf("Total Words: %d\n\n",index->totalWords);
00000135
00000136 /*array of words*/
00000137 WordType wordArray[index->totalWords];
00000138 for(k=0;k<=index->totalWords-1;k++) {
00000139 wordArray[j].count=0;
00000140 wordArray[j].word="gdfgdg";
00000141 /*printf("word: %s\n",wordArray[j].word); */
00000142 }
00000143
00000144 conductor=root;
00000145 conductor = conductor->nextWord;
00000146 if ( conductor != 0 ) {
00000147 while ( conductor->nextWord != 0 ) {
00000148 printf("%s\n",conductor->word);
00000149 /*for(k=0;k<=index->totalWords-1;k++) {*/
00000150
00000151 wordArray[j].word=conductor->word;
00000152 printf("word: %s\n",wordArray[j].word);
00000153 /*}*/
00000154
00000155 conductor = conductor->nextWord;
00000156 }
00000157 printf("%s\n",conductor->word);
00000158 }
00000159 qsort(*wordArray->word, index->totalWords, sizeof(*wordArray), comp);
00000160
00000161
00000162 return SUCCESS;
00000163 }
00000164
00000165
00000166 /****************************************************************************
00000167 * Deallocates memory used in the index.
00000168 ****************************************************************************/
00000169 void systemFree(IndexType* index)
00000170 {
00000171 WordTypePtr current, next;
00000172 current = index->headWord;
00000173 while (current != NULL)
00000174 {
00000175 next = current->nextWord;
00000176 free(current);
00000177 current = next;
00000178 }
00000179 index->headWord = NULL;
00000180 index->totalWords = 0;
00000181 }
00000182 int comp(const void *s1, const void *s2)
00000183 {
00000184 return (strcmp(*(char **)s1, *(char **)s2));
00000185 }