[Solved] Need help i get segmentation fault in program in C

A proper implementation of getfiles (gets all the files in a directory in a dynamic array) and provides a deallocator: #include <stdio.h> #include <dirent.h> #include <string.h> #include <stdlib.h> /* returns a NULL terminated array of files in directory */ char **getfilelist(const char *dirname) { DIR *dp; char **entries = NULL; struct dirent *entry; off_t index … Read more

[Solved] c++, reading string from file, segmentation fault

I’ve read Your answers, search in books and changed whole idea of reading-writing 🙂 Now when I write I use: int stringSize=text.length()*sizeof(char); file.write(reinterpret_cast<char*>(&stringSize),sizeof(stringSize)); file.write(text.c_str(),stringSize); And when I read I use: int stringSize=0; string text; plik.read(reinterpret_cast<char*>(&stringSize),sizeof(stringSize)); char * tempCharArray = new char[stringSize+1]{}; plik.read(tempCharArray,stringSize); text=tempCharArray; delete [] tempCharArray; No segmentation fault/access violation since then 🙂 I guess … Read more

[Solved] segmentation fault for vector iterator

In this declaration: vector<int>::iterator rit_i,rit_j,initial = vec.end(); only initial is initialized with vec.end(). To make it do what I think you expect, you have to write vector<int>::iterator rit_i = vec.end(), rit_j = vec.end(), initial = vec.end(); or vector<int>::iterator rit_i,rit_j,initial; rit_i = rit_j = initial = vec.end(); or something to that effect. solved segmentation fault for … Read more