Jump to content
  • Advertisement
Sign in to follow this  
subflood

pointer problems

This topic is 4725 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a function that returns a pointer to char: char * LoadAudioList Here is the variable I want to return, declared in the above function: static char playlist[TOTAL_SONGS][TRACK_LENGTH]; And the return statement: return *playlist; This is the statement the compiler is giving me a warning about char (*soundtrack)[TRACK_LENGTH]; soundtrack = LoadAudioList("soundtrack.txt"); warning: assignment makes pointer from integer without a case However, if I run the program I get exactlly what I'm supposed to be getting. I put these two statements after the assignment: puts(*soundtrack); soundtrack += 1; puts(*soundtrack); and it prints exactly what it's supposed to print.

Share this post


Link to post
Share on other sites
Advertisement
Ok. We'll ignore the fact that that's not the best way to do what you're doing. :)

It's probably complaining because you haven't declared the function LoadAudioList() as returning a char * before calling it. So, it initially assumes it returns an int.

You need to put "char *LoadAudioList(char *);" somewhere before calling the function.

Share this post


Link to post
Share on other sites
"Ok. We'll ignore the fact that that's not the best way to do what you're doing. :)"

Than what's a better way to do what I'm trying to do?

"It's probably complaining because you haven't declared the function LoadAudioList()"

Good call, I forgot to prototype the function period.

Share this post


Link to post
Share on other sites
Quote:
Original post by subflood
"Ok. We'll ignore the fact that that's not the best way to do what you're doing. :)"

Than what's a better way to do what I'm trying to do?


It's generally not a good idea to use function-local statics for this kind of thing. They are best used only for variables used locally that must retain their value between calls.

If you're using C (as opposed to C++), then a file-level static might be better. If you're using C++, then it should be a (private) member of a class.

But, in the end, if it works for you and you're happy with it, then don't worry about it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!