Hi,

I am creating a priority list which is a part of a larger program. When the function runs, it just keeps running forever without stopping. The program reads from the file and creates a priority linked list based on "priority" variable. If priority is the same, it does lexical comparison of the "mnemonic" string and prioritizes based on that. I tried inserting printf's but they fail at indicated comments.

Here is the struct, along with the global struct pointer:

Code:
struct ot_entry {
     char    mnemonic[OP_LENGTH + 1];
     int     format;                           
     char    opcode;   
     int     priority;  
     struct  ot_entry  *next;
};

struct  ot_entry  *optbl;
OP_LENGTH is 6

Here is a function:

Code:
void build_optbl()

{
	struct ot_entry *new, *curr;
	struct ot_entry *temp = NULL;
	char mnemonic[OP_LENGTH + 1]; /* temp storage of the values from file*/
	int format, priority, opcode;        

	optbl = (struct ot_entry *)malloc(sizeof(struct ot_entry)); //first node in the priority list

	fscanf(ot_fp, "%s", mnemonic);
	fscanf(ot_fp, "%d", &format);
	fscanf(ot_fp, "%x", &opcode);
	fscanf(ot_fp, "%d", &priority);
	strcpy(optbl->mnemonic, mnemonic);
	optbl->format = format;
	optbl->opcode = (char)opcode;
	optbl->priority = priority;
	optbl->next = NULL;
	
	while (!feof(ot_fp))
	{
		new = (struct ot_entry *)malloc(sizeof(struct ot_entry));
	
		fscanf(ot_fp, "%s", mnemonic);
		fscanf(ot_fp, "%d", &format);
		fscanf(ot_fp, "%x", &opcode);
		fscanf(ot_fp, "%d", &priority);
		strcpy(new->mnemonic, mnemonic);
		new->format = format;
		new->opcode = (char)opcode;
		new->priority = priority;
		new->next = NULL;
		
		curr = optbl;
		temp = NULL;
		
		while(new->priority > curr->priority)
			{
			temp = curr;
			curr = curr->next;
			}
		
		if(new->priority == curr->priority)
			{
			
			//prints here, only things with newline char

			while((strcmp(new->mnemonic, curr->mnemonic) > 0) && (curr != NULL) && (new->priority == curr->priority));
				{
                                //does not print here
				temp = curr;
				curr = curr->next;
				}
                        //does not print here either and further on
			if (curr == NULL)
				temp->next = new;
				else if (new->priority != curr->priority)
						  {
						  temp->next = new;
						  new->next = curr;
						  } 
						  else if (curr == optbl)
					  				 {
					  				 new->next = curr;
					  				 optbl = new;
					  				 }
				  				 else
					  				 {
					  				 temp->next = new;
					  				 new->next = curr;
					  				 }			 		
			
			
			}
			else if (curr == NULL)                    
					  {
					  temp->next = new;
					  }
				  else if (curr == optbl)
				  	  		 {
					  		 new->next = curr;
					  		 optbl = new;
					  		 }
					  	 else 
					  		 {
							 temp->next = new;
							 new->next = curr;
							 }
							 

	}
		
}
"temp" should keep track of the previous node and "curr" is the current node. It inserts the "new" node in between these, unless it is at the very end. Then it just appends the node to the end.

File pointer works and I've checked if the fscanf's record the values correctly.

Here is the input file:

Code:
ADD    3  18  10
ADDF   3  58  10
ADDR   2  90  10
AND    3  40  10
BASE   0  FF  50
BYTE   0  FF  50
CLEAR  2  B4  12
COMP   3  28  12
COMPF  3  88  12
COMPR  2  A0  12
CSECT  0  FF  50
DIV    3  24  13
DIVF   3  64  13
DIVR   2  9C  13
END    0  FF  50
EQU    0  FF  50
EXTDEF 0  FF  50
EXTREF 0  FF  50
FIX    1  C4  15
FLOAT  1  C0  15
HIO    1  F4  17
J      3  3C  19
JEQ    3  30  19
JGT    3  34  19
JLT    3  38  19
JSUB   3  48  19
LDA    3  00  21
LDB    3  68  21
LDCH   3  50  21
LDF    3  70  21
LDL    3  08  21
LDS    3  6C  21
LDT    3  74  21
LDX    3  04  21
LPS    3  D0  21
MUL    3  20  22
MULF   3  60  22
MULR   2  98  22
NOBASE 0  FF  50
NORM   1  C8  23
OR     3  44  24
RD     3  D8  27
RESB   0  FF  50
RESW   0  FF  50
RMO    2  AC  27
RSUB   3  4C  27
SHIFTL 2  A4  28
SHIFTR 2  A8  28
SIO    1  F0  28
SSK    3  EC  28
STA    3  0C  28
START  0  FF  50
STB    3  78  28
STCH   3  54  28
STF    3  80  28
STI    3  D4  28
STL    3  14  28
STS    3  7C  28
STSW   3  E8  28
STT    3  84  28
STX    3  10  28
SUB    3  1C  28
SUBF   3  5C  28
SUBR   2  94  28
SVC    2  B0  28
TD     3  E0  29
TIO    1  F8  29
TIX    3  2C  29
TIXR   2  B8  29
WD     3  DC  32
WORD   0  FF  50

I'm a little clueless here. Why doesn't it work?

Thanks in advance for your help.