I declare
typedef struct LABELS_STRUCT {
char *name;
int address;
} `LABELS_STRUCT;`
LABELS_STRUCT labels_array[ARRAY_LABELS];
and a function that adds a name and address the the aray
int add_data_label(char * label, int displace)
{
LABELS_STRUCT x = {label,DATA_STARTING_ADDRESS + (100 * displace)};
labels_array[initialize]=x;
initialize++;//=initialize+displace;
printf("\tAdding [%s] with offset [%d] to labels_array[%d] with address [%d]\n", label,displace,initialize,CODE_STARTING_ADDRESS + (100 * displace));
printf("\tlabels_array[%d].name=[%s] and labels_array[%d].address= [%d]\n", initialize, labels_array[initialize].name, initialize, labels_array[initialize].address);
return 1;
}
The second printf() statement prints out the data correctly but when I have another function
int get_label_address(char *label) {
int i;
printf("Getting the Label Address for [%s]\n", label);
for (i = 0; i < initialize; i++) {
printf("\t\t\tCOMPARING LABEL [%s] TO [%s] at index [%d]\n", label, labels_array[i].name,i);
if (labels_array[i].name==label) {
printf("Label_Array[%d]=[%s] Matches label=[%s] with address [%d]\n",i,labels_array[i].name,label,labels_array[i].address);
return labels_array[i].address;
}
}
return 0;
}
The debug printf() statement "COMPARING LABEL [%s] to [s]..." Loop shows that its being compared to null. When I use any other function to print the element in labels_array[i].name, it gives me a blank value for the name element but not for the address element. Lets say I have three elements that I put into the array, labey_array[1 2 and 3] will be a blank line but label_array[4 and on] will have null. So it knows it was initialized but its not showing the actual name, just a blank line.
Anyone have any ideas?