segmentation-fault

How to identify what is causing the Segmentation fault

强颜欢笑 提交于 2021-02-05 09:42:30
问题 My code's aim is to take in 2 command line arguments (inclusive of programme name), and to print out responses as shown based on the given 2nd command line argument. If the command line argument is an integer, the user's input is accepted or "Success"and if it as anything else (e.g. a string or more than one command line argument), it will be Null and the error message will be shown. This is for CS50 caesar for those who are familiar My Code is as follows: #include <stdio.h> #include <cs50.h>

Segmentation fault while checking size of bitset

眉间皱痕 提交于 2021-02-05 09:28:11
问题 I get a segmentation fault when I try to run the code below. I've tried commenting out bits of the code, and found that the while loop with the condition j < is_prime.size() is the culprit. This is puzzling to me because I perform the same check between the same values in the for loop above it, but do not get a segmentation fault. Could someone explain to me what's the issue here? I'm using GCC 4.8.2 on Linux 64. #include <bitset> #include <iostream> using namespace std; const size_t max

Segmentation fault while checking size of bitset

大城市里の小女人 提交于 2021-02-05 09:27:17
问题 I get a segmentation fault when I try to run the code below. I've tried commenting out bits of the code, and found that the while loop with the condition j < is_prime.size() is the culprit. This is puzzling to me because I perform the same check between the same values in the for loop above it, but do not get a segmentation fault. Could someone explain to me what's the issue here? I'm using GCC 4.8.2 on Linux 64. #include <bitset> #include <iostream> using namespace std; const size_t max

CS50 Speller Segmentation Fault Issue During Misspelled Words

不问归期 提交于 2021-02-05 08:41:21
问题 My code is causing a segmentation fault somewhere. I'm not entirely sure how. I don't think it's an issue with load, as the program begins listing off Misspelled words before abruptly stopping and giving me the seg fault error. // Implements a dictionary's functionality #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <ctype.h> #include "dictionary.h" #define HASHTABLE_SIZE 80000 unsigned int count = 0; // Represents a node in a hash table typedef

SPOJ - Runtime error SIGSEGV

谁说我不能喝 提交于 2021-02-05 08:33:22
问题 Following is the implementation of infix to postfix conversion, it is working fine on my computer, but as I am submitting in on SPOJ it is giving me Runtime error SIGSEGV , I am new to competitive programming and I am unable to handle such type of errors. #include <iostream> #include <stack> #include<string.h> #include<ctype.h> using namespace std; int prec(char ch){ switch(ch){ case '^' : return 3; break; case '*': case '/': return 2; break; case '+': case '-': return 1; break; default:

Segmentation fault when including glad.h

懵懂的女人 提交于 2021-02-05 07:13:25
问题 I am following the GLFW guide to getting started but I can't seem to make it run with GLAD. Here's my C file (prac.c) #include <stdio.h> #include <stdlib.h> #include<glad/glad.h> #include<GLFW/glfw3.h> void error_callback(int error, const char* description) { fprintf(stderr, "Error %d: %s\n", error, description); } int main(void) { GLFWwindow* window; if(!glfwInit()) return -1; glfwSetErrorCallback(error_callback); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT

c++ Segmentation fault when trying to reverse print an array

隐身守侯 提交于 2021-02-04 21:01:31
问题 I have a array consisting of chars like [1,2,3,4,5,.,..] and I have a loop that looks like for (size_t i = 0; i < size; ++i) os << data[i]; // os is std::ostream& This loop prints the array in the correct order without any errors. But when I use this loop to print it backwards for (size_t i = (size - 1); i >= 0; --i) os << data[i]; I get a segmentation fault error. Any reason why this can happen? 回答1: The condition i >= 0 is always true (because size_t is an unsigned type). You've written an

Taking input string from keyboard in C using pointer notation? [duplicate]

青春壹個敷衍的年華 提交于 2021-01-29 20:45:07
问题 This question already has answers here : Input with char pointer vs. char array (6 answers) Closed 5 years ago . I am trying to take in string from keyboard. When I tried this it didn't work. char *s; fgets(s,80, stdin); I get a segmentation fault when I am trying to use the above code. However when I use below code it works, and I don't get a segmentation fault. char s[81]; fgets(s, 80, stdin); Why do I segmentation fault when I try to store the string using pointer ( char *s )? 回答1: This is

Apache seg fault. krb5int_key_delete Assertion destructors_set[keynum] == 1 failed

随声附和 提交于 2021-01-29 15:55:26
问题 I use Apache 2.4.10 and Debian 8. I installed apache and most packages with apt. For long time all was good, but suddenly we started to receive seg fault. [Wed Jan 02 00:55:19.233027 2019] [mpm_prefork:notice] [pid 25161] AH00171: Graceful restart requested, doing restart apache2: ../../../src/util/support/threads.c:383: krb5int_key_delete: Assertion `destructors_set[keynum] == 1' failed. [Wed Jan 02 00:55:19.326118 2019] [core:notice] [pid 25161] AH00060: seg fault or similar nasty error

char *str vs char str[] : segmentation issue [duplicate]

╄→гoц情女王★ 提交于 2021-01-29 11:13:45
问题 This question already has answers here : Why do I get a segmentation fault when writing to a “char *s” initialized with a string literal, but not “char s[]”? (17 answers) Closed 7 years ago . #include <stdio.h> #include <conio.h> void test(char *p) { p = p + 1; *p = 'a'; } int main() { char *str = "Hello"; test(str); printf("%s", str); getch(); return 0; } When I run this code it gives segmentation error ? why is this happening. The const theory is not clear to me... whereas if I declare str