I'm getting a SIGSEV signal when running a program on HackerRank

I had made a post yesterday but I scrapped it and approached it with C++ instead of Java. I tested the code on the compiler installed on my computer and it ran fine. When I run it on HackerRank, it keeps giving me Segmentation fault. Please find the code and compiler output below. I read… Read More I'm getting a SIGSEV signal when running a program on HackerRank

Every few attempts to run my build, I get a segmentation fault. I dont understand why

So i’m getting a Segmentation fault: 11 error and I know which block is causing it, but i’m trying to understand why. std::vector<Entity> grassEntities; for (int i = 0; i < 40; i++) { grassEntities.push_back(Entity(i * 32, 592, grassTexture)); } std::vector<Entity> dirtEntities; for (int i = 0; i < 4; i++) { for (int j… Read More Every few attempts to run my build, I get a segmentation fault. I dont understand why

C++ Segmentation fault when changing (int32_t *) pointer within method call

I’m programming a server – client application with a shared utils.cpp. So the server and client use the (in utils.h) predefined methods: int listening_socket(int port); int connect_socket(const char *hostname, const int port); int accept_connection(int sockfd); int recv_msg(int sockfd, int32_t *operation_type, int64_t *argument); int send_msg(int sockfd, int32_t *operation_type, int64_t *argument); So far, so good. But since… Read More C++ Segmentation fault when changing (int32_t *) pointer within method call

Why it is a segmentation fault with this code fragment?

Here is my code about Matrix (I decided to practise OOP writing own Matrix class) Matrix.hpp #ifndef MATRIX_HEADER #define MATRIX_HEADER typedef unsigned int u_int; class Matrix { double **mtrx; u_int x, y; public: Matrix(u_int a, u_int b); Matrix(const Matrix &); ~Matrix(); double det(); Matrix operator+(const Matrix &) const; Matrix operator-(const Matrix &) const; Matrix operator*(const… Read More Why it is a segmentation fault with this code fragment?

Declaring a char pointer

I’m trying to make a login/register project and I have difficulties in declaring the char* tempUsername from this code (SIGSEVG segmentation fault) char *tempUsername, *tempPassword, *tempPasswordConfirm, *tempSecurityQuestion; /* no other declaration for tempUsername here */ std::cout<<"Enter your new username:\n"; std::cin>>tempUsername; //process stops here if(fileSearch(newFilename(tempUsername))) { std::cout<<"Username already exists! Choose another username!\n"; } else { std::cout<<"Enter… Read More Declaring a char pointer

Segmentation Fault when refrencing vectors that changed size

So I initialize a vector within a main function, and pass that vector as a reference into a function where its size changes. Now, I would imagine that the initialized vector within the main would change in size, but its not. Am I just implementing this incorrectly? #include <iostream> #include <vector> using std::vector; void createImage(vector<vector<char>… Read More Segmentation Fault when refrencing vectors that changed size

Segmentation fault when using threads on function with large arrays -C++

I am using threads for the first time and came across a weird segmentation error whenever the called function takes very large arrays. #include <iostream> #include <thread> #include <cmath> const int dimension = 100000; // Dimension of the array // Create a simple function of an array void absolut(double *vec) { double res = 0.;… Read More Segmentation fault when using threads on function with large arrays -C++