Rockbox Development > Starting Development and Compiling

Need to take off file extension from filename and display filename

(1/3) > >>

Job Van Dam:
I've been hacking away on this small, tiny cosmetic change for way too long now I gotta know, how the heck do you strip the last 4 characters from a filename and actually have the filename left over?
 
I'm not a C guy. This pointer, smointer stuff I sorta get but not enough. Any help at all would be greatly appreciated, thank you.

GodEater:
Here's one quick (and very dirty) way to do it ;)


--- Code: ---char oldfilename[13] = "filename.bmp";
char newfilename[13];
char *pointer;

pointer = strrchr(oldfilename,'.');
*pointer = '\0';

strcpy(newfilename,oldfilename);

--- End code ---

linuxstb:
Out of curiousity, what are you trying to achieve?  Rockbox already has a setting to strip file extensions when displaying filenames, is that not working somewhere?

bascule:
... or alternatively find the Rockbox code in SVN that performs that built-in function and copy it...

Job Van Dam:
Thanks tenfold GodEater. Tweaked it a bit and it works like a charm. I owe you buddy.
After I wrote that first comment I had the idea because strings in C are char arrays I could get rid of the last 4 elements in the char array and accomplish the same thing but it didn't work for some reason.  I used strlen as the index but it wanted an int as the value to put in.

linuxstb, I'm just writing a small plugin for myself that randomly selects a theme. The part where I was stumped is I wanted the name of the theme, minus the extension, to splash onscreen. It had nothing to do with functionality but it was something I wanted.
The strip_extension function you're talking about is in albumart.c . To use it I needed to add it to the plugin API but why bother when GodEater's code worked just the same and for me it was easier to undertstand.

Thanks to everyone, especially GodEater, for the patience and help. At the next meeting I'm gonna tell Canada you guys are super great. ;D

Navigation

[0] Message Index

[#] Next page

Go to full version