When I compile my code I am getting this killed message. Why is this happening and how do I fix it?
EDIT: According to Richard I may need to fix my addRec function. I'll be updating my code when (hopefully) I figure the issue.
Also this program is a playlist program that takes song information from user (and input file and orders it from greatest to least. It also allows the user to delete, print songs, show songs of one artist, and removes songs with less than a specific amount of likes.
alizah.khan@syccuxas01:~/cs260/project/project1> make
g++ -c -o main.o main.cpp
g++ -c -o songs.o songs.cpp
g++ -ggdb main.o songs.o -o output
alizah.khan@syccuxas01:~/cs260/project/project1> ls
main.cpp main.o makefile output songs.cpp songs.h songs.o songs.txt
alizah.khan@syccuxas01:~/cs260/project/project1> ./output
Killed
alizah.khan@syccuxas01:~/cs260/project/project1>
MYMAKEFILE
XXFLAGS = -Wall -Wextra -ggdb
OBJS = main.o songs.o
output: $(OBJS)
$(CXX) -ggdb $^ -o $@
songs.o: songs.cpp songs.h
clean:
rm -f $(OBJS) output
#pragma once
#include <iostream>
#include <fstream>
#include <cstring>
struct node {
char * name;
char * title;
double length;
int likes;
node * next;
};
class SongList {
public:
SongList();
~SongList();
bool add(char * & , char * & , double & , int & );
bool addRec(node * curr, node * data);
bool editLikes(char * & , char * & , int & );
const bool showAll();
const bool showArtist(node * curr,
const char * );
bool removeByLikes(int & );
bool deleteRec(node * );
const bool printRec(node * );
private:
node * head;
node * temp;
node * tail;
};
#include "songs.h"
SongList::SongList(): head(nullptr), tail(nullptr) {}
SongList::~SongList() {
}
bool SongList::add(char * & dataName, char * & dataTitle, double & dataLength, int & dataLikes) {
node * newNode = new node;
newNode -> name = dataName;
newNode -> title = dataTitle;
newNode -> length = dataLength;
newNode -> likes = dataLikes;
if (head == nullptr) {
head = newNode;
tail = newNode;
return true;
}
return addRec(head, newNode);
}
bool SongList::addRec(node * curr, node * data) {
if (data -> likes >= head -> likes) {
data -> next = head;
head = data;
return true;
}
else if (data -> likes >= curr -> likes) {
data -> next = curr;
temp -> next = data;
return true;
}
else if (curr == tail) {
tail -> next = curr;
curr = tail;
return true;
}
else {
temp = curr;
return addRec(curr -> next, data);
}
}
const bool SongList::printRec(node * curr) {
std::cout << "Name of artist is:" << curr -> name << std::endl;
std::cout << "Name of song is:" << curr -> title << std::endl;
std::cout << "How long song is:" << curr -> length << std::endl;
std::cout << "How many likes are there:" << curr -> likes << std::endl;
if (curr == tail)
return true;
return printRec(curr -> next);
}
const bool SongList::showAll() {
if (head == nullptr) {
std::cout << "List is empty/n";
return false;
}
return printRec(head);
}
const bool SongList::showArtist(node * curr,
const char * artist) {
if (curr -> name == artist) {
std::cout << "Name of artist is:" << curr -> name << std::endl;
std::cout << "Name of song is:" << curr -> title << std::endl;
std::cout << "How long song is:" << curr -> length << std::endl;
std::cout << "How many like are there: " << curr -> likes << std::endl;
}
if (curr == tail) {
return true;
}
return showArtist(curr -> next, artist);
}
bool SongList::deleteRec(node * curr) {
if (head == nullptr)
return false;
temp = curr;
delete curr;
return deleteRec(temp -> next);
}
bool SongList::removeByLikes(int & dataLikes) {
node * travPtr = head;
while (travPtr -> next -> likes > dataLikes) {
travPtr = travPtr -> next;
}
travPtr = tail;
return deleteRec(travPtr -> next);
}
#include "songs.h"
using namespace std;
int main() {
cout << "1";
ifstream inFile;
SongList list;
char medium[128];
char * artist, * sName;
double size;
int likes;
inFile.open("songs.txt");
if (inFile.fail()) {
cout << "File failed to open, please fix and run again!" << endl;
return -1;
}
while (!inFile.eof()) {
inFile.getline(medium, 128, ',');
artist = new char[sizeof medium];
inFile.getline(medium, 128, ',');
sName = new char[sizeof medium];
inFile >> size;
inFile.ignore(',');
inFile >> likes;
inFile.ignore('\n');
list.add(artist, sName, size, likes);
}
cout << "Welcome to SONGLIST! \nPlease enter your option from the menu. \n" <<
"Press (A) to add a song." <<
"Press (E) to edit the likes of a song.\n" <<
"Press (D) if you want to show all songs.\n" <<
"Press (T) if you want to show songs by artist.\n" <<
"Press (R) to remove all songs with less than m likes.\n";
return 0;
}
THIS IS THE INPUT FILE THAT I AM USING FROM SOMONE ELSE.
BTS, DYNIMITE, 3.43, 41000000
NF, CLOUDS, 1.14, 869000
HARRY, FALLING, 3.27, 30000000
RACHEL, FIGHT SONG, 3.23, 166000
RUTH, LOST BOY, 4.33, 65000
JAMES, SAY YOU WONT LET GO, 3.27 213000
HARRY, SIGN OF THE TIMES, 5.41, 63000000
IDENA, LET IT GO, 3.21, 21000000
BTS, BLACK SWAN, 3.43, 23000000
PASSENGER, LET HER GO, 4.20, 97000
KATIE, DAISIES, 2.53, 12000
BEBE, SACRIFICES, 2.40, 300000
ANDY, DONT GIVE UP ON ME, 3.16, 5600000
JUSTIN, BIGGER THAN, 3.28, 21000
SAM, IM READY, 3.20, 30500
ALEC, OH MY GOD, 3.07, 1000000
ANDY, GOOD EXAMPLE, 2.29, 15000
GREYSON, GOOD AS GOLD, 3.25, 78000
BRYNN, TELL ME IM PRETTY, 3.08, 29000
GRYFFIN, CRY, 3.38, 3000000
KHALID, FREE SPIRIT, 3.02, 55000
KYGO, LIKE IT IS, 3.03, 890000
CHAINSMOKERS, THIS FEELING, 3.17, 760000
KASKADE, WITH YOU, 3.00, 2000
LAUV, LIKE ME BETTER, 3.17, 5000000
AVA, SALT, 3.00, 56900
LEWIS, BEFORE YOU GO, 3.50, 89000
LAUV, NEVER NOT, 4.02, 76000
JEREMY, ALWAYS ILL CARE, 2.40, 68000
JAMES, IMPOSSIBLE, 4.07, 49000
GMILLER, NO TEARS LEFT TO CRY, 3.10, 770000
What I have tried:
I don't know what to do so I haven't tried anything really.
EDIT: I ran my code through this online website
https://www.onlinegdb.com/online_c++_debugger
The website said this. But I don't know which one so I tried shortening the input file and looking over my code but I still don't get it.
"If your program is reading input from standard input and you forgot to provide input via stdin.
Your program contains infinite loop, which may never break.
Your program contains infinite recursive function calls.
May be your program is trying to process large data and it takes much time to process"