how to correct an segmentation fault ?
-
below is an hackerrank question link where i am encountering an segmentation falut. HackerRank[^] and this is my solution
#include
#include
using namespace std;void fillVector(vector &temp, unsigned long number);
void RotateVector(vector &arr1, vector &arr2, unsigned long k);int main(){
unsigned long n,k,q;cin >> n >> k >> q; vector a, b; fillVector(a, n); fillVector(b, q); RotateVector(a, b, k); return 0;
}
//to rotate the vector by kth measure.
void RotateVector(vector &arr1, vector &arr2, unsigned long k){
unsigned long arraySize = arr1.size();
unsigned long querySize = arr2.size();
unsigned long rotation = k, i;
unsigned long start = rotation%arraySize; //this was causing the problem.if(rotation rotatedArray; for(i=0; i &arr, unsigned long n){ unsigned long temp; for(int i=0; i\> temp; arr.push\_back(temp); }
}
the above solution is giving segmentation fault and i am not able to detect it.(rest all the test-cases are passed) here are the links to that test case inputs : https://hr-testcases-us-east-1.s3.amazonaws.com/1884/input04.txt?AWSAccessKeyId=AKIAJ4WZFDFQTZRGO3QA&Expires=1527377038&Signature=sA5C43bnnqyLeXwWA9L16en3rEE%3D&response-content-type=text%2Fplain and expected outputs : https://hr-testcases-us-east-1.s3.amazonaws.com/1884/output04.txt?AWSAccessKeyId=AKIAJ4WZFDFQTZRGO3QA&Expires=1527377042&Signature=%2BSyDUj0B5DwySkSPGjiwfmB7MlE%3D&response-content-type=text%2Fplain Edit : Below is the working code:
#include
using namespace std;void fillVector(vector
-
below is an hackerrank question link where i am encountering an segmentation falut. HackerRank[^] and this is my solution
#include
#include
using namespace std;void fillVector(vector &temp, unsigned long number);
void RotateVector(vector &arr1, vector &arr2, unsigned long k);int main(){
unsigned long n,k,q;cin >> n >> k >> q; vector a, b; fillVector(a, n); fillVector(b, q); RotateVector(a, b, k); return 0;
}
//to rotate the vector by kth measure.
void RotateVector(vector &arr1, vector &arr2, unsigned long k){
unsigned long arraySize = arr1.size();
unsigned long querySize = arr2.size();
unsigned long rotation = k, i;
unsigned long start = rotation%arraySize; //this was causing the problem.if(rotation rotatedArray; for(i=0; i &arr, unsigned long n){ unsigned long temp; for(int i=0; i\> temp; arr.push\_back(temp); }
}
the above solution is giving segmentation fault and i am not able to detect it.(rest all the test-cases are passed) here are the links to that test case inputs : https://hr-testcases-us-east-1.s3.amazonaws.com/1884/input04.txt?AWSAccessKeyId=AKIAJ4WZFDFQTZRGO3QA&Expires=1527377038&Signature=sA5C43bnnqyLeXwWA9L16en3rEE%3D&response-content-type=text%2Fplain and expected outputs : https://hr-testcases-us-east-1.s3.amazonaws.com/1884/output04.txt?AWSAccessKeyId=AKIAJ4WZFDFQTZRGO3QA&Expires=1527377042&Signature=%2BSyDUj0B5DwySkSPGjiwfmB7MlE%3D&response-content-type=text%2Fplain Edit : Below is the working code:
#include
using namespace std;void fillVector(vector
-
below is an hackerrank question link where i am encountering an segmentation falut. HackerRank[^] and this is my solution
#include
#include
using namespace std;void fillVector(vector &temp, unsigned long number);
void RotateVector(vector &arr1, vector &arr2, unsigned long k);int main(){
unsigned long n,k,q;cin >> n >> k >> q; vector a, b; fillVector(a, n); fillVector(b, q); RotateVector(a, b, k); return 0;
}
//to rotate the vector by kth measure.
void RotateVector(vector &arr1, vector &arr2, unsigned long k){
unsigned long arraySize = arr1.size();
unsigned long querySize = arr2.size();
unsigned long rotation = k, i;
unsigned long start = rotation%arraySize; //this was causing the problem.if(rotation rotatedArray; for(i=0; i &arr, unsigned long n){ unsigned long temp; for(int i=0; i\> temp; arr.push\_back(temp); }
}
the above solution is giving segmentation fault and i am not able to detect it.(rest all the test-cases are passed) here are the links to that test case inputs : https://hr-testcases-us-east-1.s3.amazonaws.com/1884/input04.txt?AWSAccessKeyId=AKIAJ4WZFDFQTZRGO3QA&Expires=1527377038&Signature=sA5C43bnnqyLeXwWA9L16en3rEE%3D&response-content-type=text%2Fplain and expected outputs : https://hr-testcases-us-east-1.s3.amazonaws.com/1884/output04.txt?AWSAccessKeyId=AKIAJ4WZFDFQTZRGO3QA&Expires=1527377042&Signature=%2BSyDUj0B5DwySkSPGjiwfmB7MlE%3D&response-content-type=text%2Fplain Edit : Below is the working code:
#include
using namespace std;void fillVector(vector
-
You correctly define
start
Quote:
unsigned long start = rotation%arraySize;
and then miss the opportunity of using it. By the way, in my opinion, you don't even need to actually rotate the vector.