#include <stdio.h> #define MAX_NUM_LINES 6000 #define MAX_STR_LEN 100 int readCd
ID: 3805145 • Letter: #
Question
#include <stdio.h>
#define MAX_NUM_LINES 6000
#define MAX_STR_LEN 100
int readCdData(char fileName[], char csvMatrix[][MAX_STR_LEN])
{
FILE *fp;
fp = fopen("fusers/moe hajj/Desktop/assignment 5", "r");
int isReading, n, countLines;
isReading = 1;
while(isReading=1)
{
n = fgets(fileName[countLines], MAX_STR_LEN, fp);
if(n==NULL)
{
isReading=0;
}
else countLines++;
}
return n;
}
void stripNewLineAtEOS(char str[])
{
int n;
n = strlen(str);
if(str[n-1]==' ')
{
str[n-1]='';
}
}
void getSubstring(char[], int i1, int i2, char substr[])
{
int i, n, length;
length = strlen(str);
n = i2-i1;
for(i=0;i<n;i++)
{
substr[i]=str[i+i1];
}
substr[n]='';
for(i=i1;i<i2:i++)
{
substr[i-i1]=str[i];
}
}
int getCommaIndex(char str[], int index[])
{
int i, n, count;
n = strlen(str);
count = 0;
for(i=0;i<n;i++)
{
if(str[i]==',')
{
index[count]=i;
count = count+1;
}
}
return count;
}
void parseCSV_string(char csvStr[], char artist[], char title[], char year[], char genre[], char rating[], char fan[])
{
char substr[MAX_STR_LEN];
int i, n, comma[MAX_STR_LEN], i1, i2;
n = getCommaIndex(csvstr, comma);
for(i=0;i<=n;i++)
{
if(i==0)
{
i1 = 0;
}
else i1 = comma[i-1]+1;
if(i==n)
{
i2 = strlen(str);
}
getSubstr(csvStr, i1, i2, subStr);
if(i==0)
{
strcpy(artist, substr);
}
if(i==1)
{
strcpy(title, substr);
}
if(i==2)
{
strcpy(year, substr);
}
if(i==3)
{
strcpy(genre, substr);
}
if(i==4)
{
strcpy(rating, substr);
}
if(i==5)
{
strcpy(fan, substr);
}
}
}
void parseCSV_matrix(int n, char csvMatrix[][MAX_STR_LEN], char cdDB_artist[][MAX_STR_LEN],
char cdDB_title[][MAX_STR_LEN],int cdDB_year[], char cdDB_genre[][MAX_STR_LEN], float cdDB_rating[], char cdDB_fan[][MAX_STR_LEN])
{
int i;
for(i=0;i<n;i++)
{
parseCSV_string(csvMatrix[i], cdDB_artist[i], cdDB_title[i], cdDB_year[i], cdDB_genre[i], cdDB_rating[i], cdDB_fan[i]);
}
}
void printCd(int index, char cdDB_artist[][MAX_STR_LEN], char cdDB_title[][MAX_STR_LEN], int cdDB_year[],
char cdDB_genre[][MAX_STR_LEN],float cdDB_rating[], char cdDB_fan[][MAX_STR_LEN])
{
printf("%s %s %d %s %f %s", cdDB_artist[index], cdDB_title[index], cdDB_year[index], cdDB_genre[index], cdDB_rating[index, cdDB_fan[index]);
}
void printCdList(int n, int index[], char cdDB_artist[][MAX_STR_LEN], char cdDB_title[][MAX_STR_LEN], int cdDB_year[],
char cdDB_genre[][MAX_STR_LEN], float cdDB_rating[], char cdDB_fan[][MAX_STR_LEN])
{
int i;
for(i=0;i<n;i++)
{
printCd(index[i], cdDB_artist, cdDB_title, cdDB_year, cdDB_genre, cdDB_rating, cdDB_fan);
}
}
int queryByYear(int n, int minYear, int maxYear, int index[], int cdDB_year[])
{
int i, matches;
matches = 0;
for(i=0;i<n;i++)
{
if(cdDB_year[i]>=minYear && cdDB_year[i]<=maxYear)
{
index[match]= i;
match = match +1;
}
}
return match;
}
int queryByGenre(int n, char genre_of_interest[], int index[], char cdDB_genre[][MAX_STR_LEN])
{
int i, match;
matches = 0;
for(i=0;i<n;i++)
{
if(genre_of_interest[i]==cdDB_genre[i])
{
index[match]=i;
match = match + 1;
}
}
return match;
}
int queryByArtist(int n, char artist_of_interest[], int index[], char cdDB_artist[][MAX_STR_LEN])
{
int i, match;
match = 0;
for(i=0;i<n;i++)
{
if(artist_of_interest[i]==cdDB_artist[i])
{
index[match]=i;
match = match +1;
}
}
return match;
}
int queryByTitle(int n, char title_of_interest[], int index[], char cdDB_title[][MAX_STR_LEN])
{
int i, match;
match = 0;
for(i=0;i<n;i++)
{
if(title_of_interest[i]==cdDB_title[i])
{
index[match]=i;
match = match +1;
}
}
return match;
}
float queryByRating(int n, char rating_of_interest[], int index[], char cdDB_title[][MAX_STR_LEN])
{
int i, match;
match = 0;
for(i=o;i<n;i++)
{
if(rating_of_interest[i]==cdDB_title[i])
{
index[match]=i;
match = match +1;
}
}
return match;
}
int main()
{
int readData, commaCount, interestYear, interestGenre, interestTitle, interestArtist;
float interestRating;
interestRating = queryByRating();
interestYear = queryByYear(int n, int minYear, int maxYear, int index[], int cdDB_year[]);
intersetGenre = queryByGenre(int n, char genre_of_interest[], int index[], char cdDB_genre[][MAX_STR_LEN]);
intersetTitle = queryByTitle(int n, char title_of_interest[], int index[], char cdDB_title[][MAX_STR_LEN]);
intersetArtist = queryByArtist(int n, char artist_of_interest[], int index[], char cdDB_artist[][MAX_STR_LEN]);
<Artist>,<Title>,<Year>,<Genre>,<Rating>
Foo Fighters,The Colour and the Shape,1997,Rock,4.5
Jethro Tull,Aqualung,1971,Classic Rock,4.4
Kings of Leon,Only By The Night,2008,Rock,4.3
Red Hot Chili Peppers,The Getaway,2016,Funk Rock,4.8
icejjfish,What it is,2016,R&B,5.0
Lil Yachty,Lil Boat,2016,Hip-Hop,5.0
Florida Georgia Line,Dig Your Roots,2016,Country,0.0
Desiigner,New English,2016,Trap Music,5.0
DJ Khaled,Major Key,2016,Trap Music,5.0
Taylor Swift,1989,2014,pop,5.0
D.R.A.M,Big Baby D.R.A.M,2016,rap,5.0
Adele,25,2015,pop,4.0
A$AP Rocky,Long.Live.ASAP,2013,rap,4.0
Lil Wayne,Tha Carter IV,2011,rap,4.5
The Beatles,Sgt. Pepper's Lonely Hearts Club Band,1967,Classic Rock,5.0
The Beatles,Abbey Road,1969,Classic Rock,5.0
The Beatles,Magical Mystery Tour,1967,Classic Rock,5.0
The Beatles,White Album,1968,Classic Rock,5.0
The Beatles,Let It Be,1970,Classic Rock,5.0
Queen,Greatest Hits II,1991,Glam/Classic Rock,4.6
Original Broadway Cast of Hamilton,Hamilton,2015,Broadway/R&B/Hip Hop/Rap,5.0
Andrew McMahon in the Wilderness,Andrew McMahon in the Wilderness,2014,Indie Pop,4.7
Michael Jackson,Thriller,1982,Pop/Funk,4.8
Keith Kenniff,Branches,2013,Ambient Orchestral,4.7
Alestorm,Back Through Time,2011,Pirate Metal,5.0
}
my program is supposed to print out the the list the user searches, i had some errors from the compier it woulf not run. Can someone fix it.
Explanation / Answer
Thank you.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.