Hey guys, so I made a program for my class and it works great, but it gives me an abort() error so its not able to end itself correctly. The program works and does what I need it to do great but I wanna be able to get rid of the abort error. Below is my program. Feel free to try it out and see if you get the same issue. I have an idea of what might be the problem, but I still cant get my head around what to do. Thanks guys. Here is also information inside the file.
Washington George 1789 1797
Jefferson Thomas 1801 1809
Adams John 1797 1801
Monroe James 1817 1825
Madison James 1809 1817
Jackson Andrew 1829 1837
Adams John Quincy 1825 1829
Harrison William Henry 1841 1841
Van Buren Martin 1837 1841
Polk James Knox 1845 1849
Tyler John 1841 1845
Fillmore Millard 1850 1853
Taylor Zachary 1849 1850
Buchannan James 1857 1861
Pierce Franklin 1853 1857
Johnson Andrew 1865 1869
Lincoln Abraham 1861 1865
Hayes Rutherford Birchard 1877 1881
Grant Ulysses Simpson 1869 1877
Arthur Chester Alan 1881 1885
Garfield James Abram 1881 1881
Harrison Benjamin 1889 1893
Cleveland Stephen Grover 1885 1889
McKinley William 1897 1901
Cleveland Stephen Grover 1893 1897
Taft William Howard 1909 1913
Roosevelt Theodore 1901 1909
Harding Warren Gamaliel 1921 1923
Wilson Thomas Woodrow 1913 1921
Hoover Herbert Clark 1929 1933
Coolidge John Calvin 1923 1929
Truman Harry S 1944 1953
Roosevelt Franklin Delano 1933 1945
Kennedy John Fitzgerald 1961 1963
Eisenhower Dwight David 1953 1961
Nixon Richard Milhous 1969 1974
Johnson Lyndon Baines 1963 1969
Carter James Earl 1977 1981
Ford Gerald 1974 1977
Bush George Herbert Walker 1989 1993
Reagan Ronald Wilson 1981 1989
Bush George Walker 2001 2009
Clinton William Jefferson 1993 2001
Obama Barack Hussein 2009 2017
The program will get rid of the starting year, and out the ending year ahead of the president name. Also, the presidents besides the first and last one, had to be switched as well. Again, it all works but just some extra info. Just need to get rid of that abort(). Thanks again.
//Scott Maki 4/19/16
#include <iostream>
#include <fstream>
#include <string>
#include <math.h>
using namespace std;
struct link
{
//Struct for the line and pointer
string line;
link *points;
};
string Calc(string tmp);
string Calc2(string tmp2);
int main()
{
link *startptr, *workingptr;
fstream data;
string fin, temp, temp2;
//Open and check file
data.open("C:\\Users\\Scott\\Desktop\\presidents.txt");
if (data.fail())
{
cout << "Failed to open.\n";
exit(1);
}
//Create starter pointer and pull the very first president because it wont switch
startptr = new link;
workingptr = startptr;
getline(data, temp);
temp = Calc(temp);
(*workingptr).line = temp;
cout << (*workingptr).line << endl;
(*workingptr).points = new link;
workingptr = (*workingptr).points;
getline(data, temp);
//Loop for pulling in two lines, calling function, and switching names
while (!data.eof())
{
//Function to rearrange the string
temp = Calc(temp);
//Peek next line to see if the next line is real or not
if (data.peek() >= 'A')
{
getline(data, temp2);
//Function to rearrange the string
temp2 = Calc2(temp2);
//Swap line, print
(*workingptr).line = temp2;
cout << (*workingptr).line << endl;
}
//Create a new link
(*workingptr).points = new link;
workingptr = (*workingptr).points;
//Swap of the line and print
(*workingptr).line = temp;
cout << (*workingptr).line << endl;
getline(data, temp);
}
//Make null if loop is broken
(*workingptr).points = NULL;
return 0;
}
string Calc(string tmp)
{
int length;
string temp, begin, end, original;
original = tmp;
length = tmp.length();
begin = tmp.erase(length - (length), length - 4);
end = original.erase(length - 9, 9);
tmp = begin + " " + end;
return tmp;
}
string Calc2(string tmp2)
{
int length;
string temp, begin, end, original;
original = tmp2;
length = tmp2.length();
begin = tmp2.erase(length - (length), length - 4);
end = original.erase(length - 9, 9);
tmp2 = begin + " " + end;
return tmp2;