allocating memory to an array of pointers doesn't work

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi guys, what's wrong with this???

 

	char * strings[10];;

	for(int i = 0; i < 10; i++)
		strings[i] = safe_malloc(255);

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maybe you need a cast?
 

strings[i] = (char*) safe_malloc(255);

 

--Mike

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
  1. A superfluous semi-colon if we're in pedantic mode.
  2. The missing cast although necessary to prevent a warning, shouldn't result in faulty code. (Casting is very important when de-referencing a pointer however)

 

Seriously though; tell us how it fails, then you may get some sensible answers.