Skip to main content



      Home
Home » Language IDEs » C / C++ IDE (CDT) » Eclipse terminating
Eclipse terminating [message #1134776] Sat, 12 October 2013 15:17 Go to next message
Eclipse UserFriend

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 09:29 Go to previous message
Eclipse UserFriend
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: Tue May 20 03:10:30 EDT 2025

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

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

Back to the top