I have a problem with the segmentation fault.
Look:
#include<fstream>
using namespace std;
int main(){
int n,i,vector[10001],vectorcopy[10001];
ifstream in("program.in");
ofstream out("program.out");
in>>n;
for(i=1;i<=n;i++){
in>>vector[i];
vectorcopy[i]=vector[i];
}
return 0;}
And the debugger says:
Program recived signal SIGSEGV, Segmentation fault
Please, tell me what to do!
Your program is (mostly) working correctly, if the input file
program.inis correct. I suppose your segmentation fault error is caused by:I got no errors with this
program.ininput file:Other errors
I said “mostly” because there are a few other errors in your program. They are not causing trouble (C++ calls this “undefined behaviour”) right now, but sooner or later they will:
for an array of size
n, indexes start at 0 and end atn - 1; when using arrays, do not write yourforstatement like this:just rewrite it as:
vectorcopyarrayprogram.outoutput file