-1

So I am working on implementing the KnapSack problem, using the Branch and Bound algorithm. I have finished implementing it but I am getting some weird compiling errors which I have no idea how to fix:

COMPILING ERRORS

gcc -Wall -pedantic -g -std=c99   -c -o bnb.o bnb.c
bnb.c: In function ‘branch_and_bound’:
bnb.c:225: warning: cast from pointer to integer of different size
bnb.c:229: warning: implicit declaration of function ‘copy_string’
bnb.c:248: warning: cast from pointer to integer of different size
bnb.c:251: error: ‘struc_sol’ has no member named ‘string’
bnb.c:260: error: ‘struc_sol’ has no member named ‘string’
bnb.c:260: warning: cast from pointer to integer of different size
bnb.c:263: error: ‘struc_sol’ has no member named ‘string’
make: *** [bnb.o] Error 1

Any suggestions on what I am doing wrong?

Sarah
  • 313
  • 3
  • 10
  • Which _error_ message don't you understand? – timrau Mar 18 '14 at 17:35
  • Please provide a minimal example. I am not inclined to go through 300+ lines of code – Niklas B. Mar 18 '14 at 17:35
  • A brief Google search of each individual error should give you a decent idea of what the problem is and what is needed to fix it. If you have a problem understanding a specific one, eliminate parts of the code until there's nothing left but that error, and post that in a question. – Bernhard Barker Mar 18 '14 at 17:38

1 Answers1

1

bnb.c:225: warning: cast from pointer to integer of different size

This is from the line:

     topNode->solution_vec[i] = (int)malloc(sizeof(int));

Just as the message mentioned, malloc() returns a pointer. You shouldn't cast it into an integer. Indeed, you don't need to allocate memory for solution_vec[i] at all since it's already allocated by the earlier allocation of topNode.


bnb.c:229: warning: implicit declaration of function ‘copy_string’

Check if copy_string() was declared in your header files.


bnb.c:251: error: ‘struc_sol’ has no member named ‘string’

Just as it mentioned, struc_sol has no member called string and thus child1Node->string leads to syntax error.

timrau
  • 22,578
  • 4
  • 51
  • 64