[Solved] Segmentation Fault while comparing strings

The compare function shall satisfy the principle of weak ordering. Change the function the following way static bool compareStrings( const overview_table &a_timestamp, const overview_table &b_timestamp ) { return a_timestamp.n_timestamp < b_timestamp.n_timestamp; } solved Segmentation Fault while comparing strings

[Solved] where is the pthread segfault happening?

You use of strtok() is wrong: line = strtok(buffer, NULL); should be line = strtok(NULL, delim); Another mistakes should be fixed similarly. The elements of text_lines are uninitialized: text_lines = malloc(6000 * sizeof(char*)); this allocated 6000 pointers to char, but none of these pointers are initialized. 0 solved where is the pthread segfault happening?

[Solved] C/SDL – Segmentation fault when program run multiple times in succession [closed]

Let me break down a debugging session for you, but in future you better do that yourself. If the problem can be easily reproduced, it is quite trivial to fix it: gdb ./GAME (gdb) r Program received signal SIGSEGV, Segmentation fault. 0x00007ffff7b2d10c in ?? () from /usr/lib/x86_64-linux-gnu/libSDL2-2.0.so.0 (gdb) bt #0 0x00007ffff7b2d10c in ?? () from … Read more

[Solved] Function to turn a Binary Tree into the sums of all nodes below each node; segmentation fault if I don’t create a new binary tree [closed]

It is a nuisance when we have to create an MCVE from fragments of a program. However, it’s doable β€” it’s a pain, but doable. Here’s my variation on your code. Of the 115 lines shown, 35 are what you wrote in the question β€” roughly. So, I had to create twice as much code … Read more

[Solved] Last word is Failing …?

Try this: #include <stdio.h> #include <stdlib.h> #include <string.h> FILE *fr; int main (int argc, const char * argv[]){ char line[1024]; double uppercase = 0, lowercase = 0; int x = 0; fr = fopen (“PercenUpLow.txt”, “rt”); if (fr == NULL) { printf (“Can’t open file”) ; return EXIT_FAILURE ; } while(fgets(line, 1024, fr) != NULL) … Read more

[Solved] Segmentation Fault on return of main function [closed]

Look at your loop here: for(int i=0; i<3*n; i++) { all[j].h = b[i].h; all[j].w = min(b[i].w,b[i].l); all[j].l = max(b[i].w, b[i].l); j++; // increment all[j].h = b[i].l; all[j].w = min(b[i].w,b[i].h); all[j].l = max(b[i].w, b[i].h); j++; // increment again all[j].h = b[i].w; all[j].w = min(b[i].l,b[i].h); all[j].l = max(b[i].l, b[i].h); j++; // increment once again } Look at … Read more

[Solved] Learning C, segfailt confusion

You should build your code with -Wall flag to compiler. At compile time it will then print: main.c:9:15: warning: β€˜coord1’ is used uninitialized in this function [-Wuninitialized] This points you to the problem. coord1 is a pointer type, that you assign to, but coord1 has no memory backing it until it is initialized. In the … Read more

[Solved] Segmentation fault occurs in C program

As sjsam pointed out, this statement is wrong: arr=(int **) malloc(sizeof(int )*n); Your program works on systems where sizeof(int) == sizeof(int*) (i.e. 32-bit systems), but will likely fail on 64-bit ones (on which sizeof(int) == 4 and sizeof(int*) == 8. i want to create a 2d array dynamically of dimension n by q We understand … Read more

[Solved] CPP- I am getting Segmentation fault (core dumped)?

That’s why there are debug tools like gdb (just google for it πŸ˜‰ ). This is the backtrace: #0 0x00000000004009ba in node::setnext (this=0x0, x=0x614cc0) at a.cpp:25 #1 0x0000000000400c18 in list::insertend (this=0x7fffffffdf10, x=45) at a.cpp:109 #2 0x00000000004008df in main () at a.cpp:137 that means in line 137 there is a function call (l.insertend(45)), then in line … Read more

[Solved] why does the following code produce segmentation fault [duplicate]

WHere does your string point to? Nowhere! That’s why you have segmentation fault. You have to either allocate variable on stack as array or define it as pointer and later allocate memory using malloc. When using malloc, don’t forget to include “stdlib.h” Either do this: char str[6]; strcpy(str,”C-DAC”); or char *str=malloc(sizeof(*str) * 6); strcpy(str,”C-DAC”); solved … Read more