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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help: Text file to an Array Problem.

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 get 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.

If its all wrong, please tell me that as well.
Thank you in advance for any help you can give me.
Scott

 
well you should be able to just use this to chop the .mp3 off:

*strstr(string, &quot;.mp3&quot;) = '\0';
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top