Hey, im trying to use pointers with a struct. I am having an issue in the function searchData. I can not get the pointer to compair with the string, it is still just compairing the actual adress or something else. Not sure if i even passed it right. Please help you can, thank you
-Scott
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
enum mediaType {CD, TAPE, MP3};
struct Song
{char title[20];
char artist[20];
mediaType medium;
float cost;
};
Song *getData(ifstream&);
void searchData(Song*[200], string, int);
int main()
{
ifstream indata;
indata.open("song.txt");
string artistName;
Song *songs[200];
int x=0;
cout << "Input Artist Name.\n";
cin >> artistName;
*songs = getData(indata);
searchData(&songs[200], artistName, x);
system("PAUSE");
return 0;
}
//*************************************************************
Song *getData(ifstream &indata)
{
Song *songs = new Song[200]; // points variable songs to a new array -> Song[]
Song info;
int x=0;
char tempMedium;
while(indata.eof()) // reads song info
{
indata >> info.artist;
indata >> info.title
>> tempMedium
>> info.cost;
switch( tempMedium ) // converts media type
{
case 'C':
info.medium = CD;
break;
case 'T':
info.medium = TAPE;
break;
case 'M':
info.medium = MP3;
break;
}
songs[x] = info; // writes info as a line in songs[]
x++;
}
return songs;
}
//**********************************************************************
void searchData(Song *songs[200], string artistName, int x)
{
if (songs[x]->artist == artistName)
{
cout << x << endl;
// searchData(songs[200], artistName, x++);
}
}