Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search



Donate

Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Rockbox Ports are now being developed for various digital audio players!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  converting char* to char *
« previous next »
  • Print
Pages: [1]

Author Topic: converting char* to char *  (Read 4504 times)

Offline mschneider

  • Member
  • *
  • Posts: 235
converting char* to char *
« on: January 16, 2008, 08:28:30 PM »
I'm switching between two different plugins with the audio stopped, and I'm trying to retain some ID3 information. What I'm doing is stopping the audio and saving the path of the currently playing track as a file. I then enter the plugin and try to load ID3 information about the stopped file from the saved path. The functions i am using take different pointers though and the strings seem to be incompatible.

Here is the information saving:
Code: [Select]
struct mp3entry *id3 = audio_current_track();
fd = rb->open("./path.txt", O_RDWR|O_CREAT);
rb->fdprintf(fd, id3->path);
rb->close(fd);
audio_stop();

I then try to read the line of the file with the path into a buffer and then use that path to get the id3 information with rb->mp3info.

Code: [Select]
char* buf;
char *buf2;
struct mp3entry *id3

fd = rb->open("./path.txt", O_RDONLY);
rb->read_line(fd, buf, 150);
buf2 = buf;
rb->mp3info(*id3, buf2);

The read_line function takes char* buf though and the rb->mp3info function takes char *filename. Is there any way to do this?
« Last Edit: January 16, 2008, 08:32:27 PM by mschneider »
Logged

Offline saratoga

  • Developer
  • Member
  • *
  • Posts: 8963
Re: converting char* to char *
« Reply #1 on: January 16, 2008, 09:03:42 PM »
Quote from: mschneider on January 16, 2008, 08:28:30 PM

The read_line function takes char* buf though and the rb->mp3info function takes char *filename. Is there any way to do this?

Both of those have type "char *".  "buf" and "filename" are just variable names, not types themselves.  Have you tried printing buf ?  My guess is it contains something other then the file path and therefore the call to mp3info() fails, but I'm not really sure.
Logged

Offline mschneider

  • Member
  • *
  • Posts: 235
Re: converting char* to char *
« Reply #2 on: January 17, 2008, 07:26:11 PM »
I have tried nearly everything I can think of. Everything either says that the pointer is without a cast or prints nothing into the buffer. Are there any other ways to load the Id3 information of a stopped track?
Logged

Offline GodEater

  • Member
  • *
  • Posts: 2829
Re: converting char* to char *
« Reply #3 on: January 18, 2008, 03:27:26 AM »
Looking at your code again, I don't think it's the char* that's causing the error message you're seeing, I think it's your id3 struct.

You have :
Code: [Select]
struct mp3entry *id3

rb->mp3info(*id3, buf2);

And what I *think* you should have is :

Code: [Select]
struct mp3entry id3;

rb->mp3info(&id3, buf2);
Logged

Read The Manual Please

Offline LinusN

  • Member
  • *
  • Posts: 1914
Re: converting char* to char *
« Reply #4 on: January 18, 2008, 03:36:16 AM »
GodEater is correct. Check out apps/plugins/properties.c to see how it is done.
Logged
Archos Jukebox 6000, Recorder, FM Recorder/iAudio X5/iriver H1x0, H3x0/Toshiba Gigabeat F20/iPod G5, G5.5

Offline linuxstb

  • Developer
  • Member
  • *
  • Posts: 1163
Re: converting char* to char *
« Reply #5 on: January 18, 2008, 03:42:11 AM »
Also, (as you can see in properties.c), you should use the more general get_metadata() function on the swcodec targets (i.e. everything apart from Archos), and mp3info for hwcodec (i.e. Archos).

EDIT: Your call to read_line is also wrong - it will write into the buffer pointed to by "buf", but it doesn't point anywhere...  Instead of declaring buf as "char* buf", you should declare it as "char buf[MAX_PATH];".
« Last Edit: January 18, 2008, 03:56:34 AM by linuxstb »
Logged

Offline GodEater

  • Member
  • *
  • Posts: 2829
Re: converting char* to char *
« Reply #6 on: January 18, 2008, 03:55:06 AM »
...and looking again, in your first post, I see you have two definitions of your id3 struct.

First you had :
Code: [Select]
struct mp3entry *id3 = audio_current_track();

and then further down you had:
Code: [Select]
struct mp3entry *id3;    //although yours was missing the ';' :D

The first one is ok, because the audio_current_track() call sorts out getting the memory that the id3* pointer is "looking" at.

The second one (I assume in another function? Although it's hard to tell without seeing all your code) *isn't* okay - because all you've said is "this is a pointer", you've not actually got it pointing to any memory anywhere.

So either you need to pass the value obtained from the first call to audio_current_track() into the second definition of id3 somehow, or do the call again.

And in any event, when you have it defined as a pointer, when you end up calling mp3info() - (although don't - do what linuxstb said!) - you do it like this :

Code: [Select]
rb->mp3info(id3,buf2);      // i.e. without the '*' on the front of id3

Using the '*' tells the compiler to dereference the pointer (i.e. use what it's pointing at), and you just want the value of the pointer itself to go to mp3info (i.e. where it's pointing).
Logged

Read The Manual Please

Offline mschneider

  • Member
  • *
  • Posts: 235
Re: converting char* to char *
« Reply #7 on: January 18, 2008, 09:14:44 PM »
First off, thanks for all of your help. I've tried doing what you advised and as far as I can tell it should work for what I am trying to accomplish - but I've run into a few compiler warnings. Here's my entire code (the first section in my first post refers to how I am saving the path of the currently playing file), this is how I am trying to access the ID3 information:
Code: [Select]
int goto_track(void)
{


    int fd;
    char* current_track[MAX_PATH];
    struct mp3entry id3;

    fd = rb->open(TEMP_PATH, O_RDONLY);
    rb->read_line(fd, current_track, MAX_PATH);
    rb->close(fd);  
    fd = rb->open(current_track, O_RDONLY);
#if (CONFIG_CODEC == SWCODEC)
    if (fd >= 0 && rb->get_metadata(&id3, fd, current_track))
#else
    if (!rb->mp3info(&id3, current_track));
#endif
    rb->close(fd);

}

Here are the compiler warnings I am getting:

Code: [Select]
CC tesplugin.c
testplugin.c: In function 'goto_track':
testplugin.c:375: warning: passing argument 2 of 'rb->read_line' from incompatible pointer type
testplugin.c:377: warning: passing argument 1 of 'rb->open' from incompatible pointer type
testplugin.c:379: warning: passing argument 3 of 'rb->get_metadata' from incompatible pointer type
testplugin.c:385: warning: control reaches end of non-void function
LD testplugin.elf
OBJCOPY testplugin.rock
MAKE in shortcuts
make[3]: Nothing to be done for `all

Again, thanks for all the help.
Logged

Offline linuxstb

  • Developer
  • Member
  • *
  • Posts: 1163
Re: converting char* to char *
« Reply #8 on: January 19, 2008, 04:04:17 AM »
You've defined "current_track" to be an array of pointers to char.

It should be "char current_track[MAX_PATH]";

The last warning is because you've defined your function to be of type "int" - meaning that it should return an integer (e.g. you could use 0 for success, -1 for failure).  
Logged

  • Print
Pages: [1]
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Starting Development and Compiling
| | |-+  converting char* to char *
 

  • SMF 2.0.17 | SMF © 2019, Simple Machines
  • Rockbox Privacy Policy
  • XHTML
  • RSS
  • WAP2

Page created in 0.106 seconds with 22 queries.