Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I amost have it, but not yet, please help.

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Here is the code I have so far.


#include <stdio.h>
#include <string.h>

#define MAXLIN 150
int main()
{
FILE *f1;
char string[MAXLIN];
char got[MAXLIN];
static char mname[MAXLIN];
int fi = 0;
f1=fopen(&quot;all.m3u&quot;, &quot;r&quot;);
while ( fgets( string, MAXLIN, f1) != NULL)

if (string[0] != '#')
{
strcpy(got,strrchr(string,'\\'));
strcpy(mname,(&got[1]));

printf(&quot;%s&quot;,mname);
fi++;
}
return(0);
}


What I'm trying to do is put the mname variable into an array like umame[fi][0], so that I can then move back and forth through it in a loop,

Here is some of the all.m3u file to show structure:
#EXTM3U
#EXTINF:247,2 Unlimited - Twilight Zone
\\csgld420\MUSIC\My Music\2 Unlimited - Twilight Zone.mp3
#EXTINF:355,A-Ha - Take On Me (Tecno Mix)
\\csgld420\MUSIC\My Music\A-Ha - Take On Me (Tecno Mix).mp3
#EXTINF:216,Abc - How To Be A Millionaire
\\csgld420\MUSIC\My Music\ABC - How To Be A Millionaire.mp3
#EXTINF:209,Abc - Look Of Love
\\csgld420\MUSIC\My Music\ABC - Look of Love.mp3
#EXTINF:265,Abc - When Smokey Sings
\\csgld420\MUSIC\My Music\ABC - When Smokey Sings.mp3
#EXTINF:343,AC\DC - For Those About To Rock
\\csgld420\MUSIC\My Music\ACDC - For Those About To Rock.mp3
#EXTINF:211,AC\DC - You Shook Me All Night Long
\\csgld420\MUSIC\My Music\ACDC - You Shook Me All Night Long.mp3
#EXTINF:211,Ace Of Base - All That She Wants
\\csgld420\MUSIC\My Music\Ace Of Base - All That She Wants.mp3

Now my code gives me almost what I want, but I can't seem to put it into any array, I various errors.

Here is an example of the output from the code I have so far:

2 Unlimited - Twilight Zone.mp3
A-Ha - Take On Me (Tecno Mix).mp3
ABC - How To Be A Millionaire.mp3
ABC - Look of Love.mp3
ABC - When Smokey Sings.mp3
ACDC - For Those About To Rock.mp3
ACDC - You Shook Me All Night Long.mp3
Ace Of Base - All That She Wants.mp3

Which is fine, but I need to wack the CR and the &quot;.mp3&quot; off the end still.

I want to be able to call the array like this in the end.

printf(&quot;%s&quot;,newname[fi]); /* or newname[32] */
load_amp(newname[fi],0);

I have tried:
strcpy(newname[fi],mname); but it errors and GPF when ran
newname[fi] = mname; same as above

I need the info to look like this in the end:
newname[0] = 2 Unlimited - Twilight Zone
newname[1] = A-Ha - Take On Me (Tecno Mix)
newname[2] = ABC - How To Be A Millionaire
newname[3] = ABC - Look of Love
newname[4] = ABC - When Smokey Sings
newname[5] = ACDC - For Those About To Rock
newname[6] = ACDC - You Shook Me All Night Long
newname[7] = Ace Of Base - All That She Wants

or newname[0][0] = 2 Unlimited - Twilight Zone

I'm not sure,

Please tell me what I'm doing wrong.
Thank you in advance for any help you can give me.
Scott





 
If you are using Microsoft's VC++ there is an easier way to do this and that would be a CStringList

if not, you need to declare a 2 dimentional array of characters

#define MAXLIN 150
#define MAXTITLES 200

main
...
char data[MAXTITLES][MAXLIN];
//get the string
// keep track of the current index

sprintf(data[current_index],&quot;%s&quot;,string_read_in);



Hope this helps

Matt
 
That was so much help Zyrenthian, you made my day.

The only problem I have now is that any MAXTITLES above 3000 gives me:Exiting due to signal SIGSEGV
Stack Fault at eip=00001596
eax=00000001 ebx=000082a9 ecx=00000000 edx=0000033f esi=00000054 edi=0000fbe4
ebp=0008fbd8 esp=ffffd2b8 program=C:\DJGPP\ALLEGRO\EXAMPLES\EX11.EXE
cs: sel=00af base=82a90000 limit=0009ffff
ds: sel=00b7 base=82a90000 limit=0009ffff
es: sel=00b7 base=82a90000 limit=0009ffff
fs: sel=0087 base=0000b280 limit=0000ffff
gs: sel=00c7 base=00000000 limit=0010ffff
ss: sel=00b7 base=82a90000 limit=0009ffff
App stack: [0008fbe4..0000fbe4] Exceptn stack: [0000fb40..0000dc00]

Call frame traceback EIPs:
0x00001596


The Thing is that I need it to be like 10000.

Is it something in my code?

#include <stdio.h>
#include <string.h>

#define MAXLIN 150
#define MAXTITLES 4000

int main()
{
FILE *f1;
char string[MAXLIN];
char got[MAXLIN];
static char mname[MAXLIN];
char data[MAXTITLES][MAXLIN];
int ln,fi = 0;
f1=fopen(&quot;all.m3u&quot;, &quot;r&quot;);
while ( fgets( string, MAXLIN, f1) != NULL)
if (string[0] != '#')
{
strcpy(got,strrchr(string,'\\'));
strcpy(mname,(&got[1]));
*strstr(mname, &quot;.mp3&quot;) = '\0';
sprintf(data[fi],&quot;%s&quot;,mname);
//printf(&quot;%s&quot;,mname);
fi++;
}
printf(&quot;%s&quot;,data[26]); //just a test
printf(&quot;%s&quot;,data[423]); //checking that the array is working
return(0);
}


Is there a way to define the length after the line is read from the file, or how can I make it not GPF.

It comiles fine but GPFs when ran if MAXTITLE is above 3000.

Thanks for the help.





 
What are you doing with the information once you read it in? Are you writing it to a file, just the screen... do you need to keep it stored in an array? If you dont need an array i would suggest maybe just reading the data into a large string.

Declaring char array[10000][150] will require 1500000 bytes of memory to use.

If you could explain the extent of the program I may be able to help a bit more

Matt
 
I need to keep it in the array, so I can move backwards and forwards through the song titles, so I can play them in the code for the mp3 player.
The catch is that there will be no keyboard, mouse, or screen attached to the cpu running the final code.
Only a 4x40 LCD screen, and I need to be able to read any length .m3u file I may throw in there. I will be tracking the mouse movement speed for scrolling through the 10000 mp3s, so faster up will move through the list faster, and down will move backwards.

Its the ability to move to any entry that I need at any second that I need it.

I listed a snipit of the m3u file I use above.

Is there a better way to seek forwards and backwards through a text file fast?

Thank you again for your help.
 
Do you have any experience with a linked list? This might be the way to go as well.

Are you using Microsoft visual c++?

Matt
 
No I'm using DJGPP, because I'm poor. :(

I did get it to work, and play the mp3s, but the 3000 limit is still there, I can work around this, but it would be nice to be able to fix it.

It's pretty ugly to look at, and because I'm new, its all in main() :)

The weird thing is that it just GPFs in 95, with anything.
but it seems to work fine in ME,98,98se,2000.

But it will end up running in Linux. I figured DJGPP is pretty close to Linux's.
Thanks again for your help.



 
i am not much of a programmer any more and i would love to find someone to help me get back into programming. to give you and idea of my experience . the last lang i programmed in was fortran. but I have a suggestion that does not require knowledge in one lang. since all you want is for it to list through 10000 titles why not just use different names for the arrays. each array would hold 3000 titles and you would not have to store them all in the array at the same time. you would just simple have each array load when the other was exhausted.this way you could have an unlimited list
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top