Right, I've had a bit of a mess around with the program. Now the information is stored in an array of structures (The trim function just gets rid of the spaces at the beginning and end of strings so that can be ignored). The store function takes the different information (tracknumber, title, artist etc.) and stores it into the write place using a pointer to the array in the main function.
Again, the problems occuring when the program reaches the store function.
I'm getting these warnings but don't really follow what they mean (I'm still fairly new to this). I'm passing the array into the function as I would any other variable but it just doesnt seem to work.
Code:
warning C4047: 'function' : 'struct mp3info ** ' differs in levels of indirection from 'struct mp3info (*)[100]'
'store' : different types for formal and actual parameter 2
Herer's the code. Please let me know if you can see where I'm going wrong
Code:
/* A program to take information from a .txt file and store it in structures */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <console_lib.h>
#include <conio.h>
typedef struct mp3info
{
char title[100];
char artist[100];
char album[100];
char genre[100];
} SONG;
/* ------------------------------------------------------------------------ */
char *trim ( char *string )
{
int length = strlen ( string );
int start = 0;
int end = length - 1;
char *trimmed;
int n = 0;
/* Check to make sure a string has been input into function */
if ( string == 0 )
printf ( "Error: string to be trimmed has a null value\n" );
/* Find the first letter in the string that is not a space bar */
while ( string[start] == ' ' )
start++;
/* Find the last letter in the string that is not a space bar */
while ( string[end] == ' ' )
end--;
/* Allocate memory for trimmed string */
trimmed = ( char *) malloc ( 2 + end - start );
/* Copy new string */
strncpy (trimmed, string + start, end - start + 1);
/* Add null terminator */
trimmed[end] = 0;
return trimmed;
}
/* ------------------------------------------------------------------------ */
void store ( char string[500], SONG *array[100] )
{
char delim[] = "-";
char *token = NULL;
int tracknumber;
/* Extract track number */
token = strtok ( string, delim );
tracknumber = atoi ( token );
/* Extract and store title */
token = strtok ( NULL, delim );
token = trim ( token );
strcpy ( array[tracknumber]->title, token );
free ( token );
/* Extract and store artist */
token = strtok ( NULL, delim );
token = trim ( token );
strcpy ( array[tracknumber]->artist, token );
free ( token );
/* Extract and store album */
token = strtok ( NULL, delim );
token = trim ( token );
strcpy ( array[tracknumber]->album, token );
free ( token );
/* Extract and store genre */
token = strtok ( NULL, delim );
token = trim ( token );
strcpy ( array[tracknumber]->genre, token );
free ( token );;
}
/* ------------------------------------------------------------------------ */
int main (void)
{
char string[500];
int tracknumber = 0;
SONG array[100];
/* Open file mp3list.txt for reading */
FILE *fp;
fp = fopen ( "C:\\mp3list.txt", "r" );
/* Store the info for the first 100 mp3s */
do
{
fgets ( string, 500, fp );
store ( string, &array );
}
while ( tracknumber < 100 );
printf ( "Loading Complete!\n\n");
return 0;
}