1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#pragma warning(disable : 4996)
typedef struct {char performerName[30], songName[30]; int year, playTime, count;} Songs;
main() {
Songs songList[10] = {{"Ed Sheeran\t", "Perfect Place", 2019, 253}, {"BTS\t\t","Fire\t",2016, 209}, {"Taylor Swift\t", "Love Story", 2008, 260}, {"Earth, Wind & Fire", "September", 1978, 288}, {"Imagine Dragons\t", "Believer", 2017, 204}, {"Neoni\t\t","Loser\t", 2021, 201}, {"Imagine Dragons\t", "Enemy\t", 2021, 174}, {"Mona\t\t", "ABC\t", 2012, 92}, {"MariahCareyVEVO\t", "Star\t", 2017, 242}, {"Adele\t\t", "Hello\t", 2015, 295}};
Songs total, search;
total.count = 0;
printf("Performer's Name to search > ");
scanf(" %[^\n]", &search.performerName);
printf("Song\t\tYear released\t\tPlaying Time\n");
printf("---------------------------------------------------------------------\n");
for (int i = 0; i < 10; i++) {
//if (strcmp(songList[i].performerName, search.performerName) == 0) {
if (strcmp(songList[i].performerName, search.performerName) == 0) {
printf("%s\t%d\t\t%ds\n", songList[i].songName, songList[i].year, songList[i].playTime);
total.count += 1;
}
}
printf("---------------------------------------------------------------------\n");
printf("%d records found for Performer's Name = %s\n", total.count, search.performerName);
system("pause");
}
|