Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » C / C++ IDE (CDT) » Eclipse terminating
Eclipse terminating [message #1134776] Sat, 12 October 2013 19:17 Go to next message
Andy yang is currently offline Andy yangFriend
Messages: 1
Registered: October 2013
Junior Member

Sorry noob question.

The program is suppose to select a file, sort it and print the sorted array. This works on my school's server but with eclipse, the program stops after i enter the file name.
i get the following

"Enter file name: a.txt
Press any key to continue . . . "

What am i doing wrong ?

here is the code im trying to run

#include <iostream>
#include <string>
#include <fstream>

void insertion_sort(int x[],int length)
{
int key,i;
for(int j=1;j<length;j++)
{
key=x[j];
i=j-1;
while(x[i]>key && i>=0)
{
x[i+1]=x[i];
i--;
}
x[i+1]=key;
}
}



int main()
{

int array[20];
int size = 20;
int x;
using namespace std;
char name[256];
string sort;
cout << "enter a file\n";
cin >> name;
ifstream file(name);
if(file.is_open())
{

for(int i = 0; i < 20 ; ++i)
{
file >> array[i];
}

cout << "enter a sort method - type insertion_sort or merge_sort or quick_sort or counting_sort\n";
cin >> sort;

if (sort == "insertion_sort")

{
cout << "asdfasdfsdf";
insertion_sort(array,20);
cout << "\ninsertion sort";
}

if ( sort != "merge_sort" && sort != "insertion_sort" && sort != "insertion_sort" && sort !=
"insertion_sort" )
{
cout << "none was chosen";

}

cout<<endl<<"sorted "<<endl;
for(x=0;x<size;x++)
{
cout<<array[x]<<endl;
}


}
else
cout << "file doesnt exist";
return 0;
}





Re: Eclipse terminating [message #1137417 is a reply to message #1134776] Mon, 14 October 2013 13:29 Go to previous message
David Wegener is currently offline David WegenerFriend
Messages: 1351
Registered: July 2009
Senior Member
Note that this is not a case of Eclipse terminating, it is your program that is terminating. From your explanation, Eclipse appears to continue running.

The problem is likely that the file is not being found. When you start a process, it runs in a working directory. Files referenced by the program are looked for relative to that location. You can define the working directory where Eclipse launches your program on the Launch Config dialog (Run->Run Configurations). Changing this to the directory containing the file should help. You could also specify the absolute path to the file when prompted by the program.
Previous Topic:Environment variable for each project
Next Topic:F5/F6/F7: xorg freezes for 1-2 seconds
Goto Forum:
  


Current Time: Fri Dec 19 04:13:37 GMT 2014

Powered by FUDForum. Page generated in 0.06965 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software