C++ :: Deleting Vector With Char - Segment Fault

Apr 19, 2012

The below code is giving me segment fault during delete [] (*iter) sometimes. Is it not the proper way to delete the vector with char *

Code:
#include <iostream>
#include <vector>
using namespace std;
int main() {
vector<char*> nameList;
for (int i=0;i<1000;++i)

[Code] ....

View 7 Replies


ADVERTISEMENT

C++ :: Printf Is A Part Of Code Segment But Found In Data Segment?

Sep 28, 2013

printf is a part of code segment but found in data segment.....why is it so ?

View 7 Replies View Related

C++ :: SDL Deleting From Vector

Apr 13, 2013

Simple rect collision detection

bool check_collision(SDL_Rect *box1, SDL_Rect *box2){
if(box1->x+box1->w<=box2->x)return false;
if(box1->x>=box2->x+box2->w)return false;
if(box1->y+box1->h<=box2->y)return false;
if(box1->y>=box2->y+box2->h)return false;

return true;

[Code] ...

The order of the game is of course standard.

1.handle input
2. handle logic
3. render
4. update

It's all pretty simple and straight forward, but oftentimes (not always) when the weapon hits the asteroid, the program crashes. If for example I turn off the delete main_weapon[i] and main_weapon.erase(main_weapon.begin()+i); the program works perfectly, but of course the bullets go right though the asteroid object, which is not what I want. It's only the weapon deletion which is causing no end of trouble.

View 7 Replies View Related

C++ ::  Deleting Vector Of Pointers?

Nov 23, 2013

Currently I am implementing the A* algorithm in C++. I have chosen to use a hybrid of a '2D vector grid' and two 1D pointer vectors to specific places in the '2D vector grid'. I have chosen to do it this way, so I can access the nodes using coordinates and also for iterating over the appropriate nodes(rather than the whole '2D vector grid').

In the below examples I have not included the full code because I deemed it irrelevant to the question.

vector <int> CInGame::AStarAlgorithm(vector<vector<bool>>& resistanceMap, int startX, int startY, int targetX, int targetY, int cutOff) {
vector <int> returnVec;
vector <vector<CNode>> twoDimNodes;
vector <CNode*> openSet;
vector <CNode*> closedSet;

[code].....

The error is:

_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)

do I need to free the pointers or is it done automatically? If not then how would I do this?

View 3 Replies View Related

C++ :: Deleting Vector Of Pointers?

Oct 14, 2014

I made a vector of pointers and the problem is that I have trouble deleting the pointers in the vector. I used to simply do vector.clear() or vector.erase() however it does not clear the actual memory. And I tried something like this:

std::vector<Foo*> Vector;
std::vector<Foo*>::iterator i;
for (i = Vector.begin(); i < Vector.end(); i++)
delete *i;

View 5 Replies View Related

C++ :: Repeat Found - Deleting In A Vector

Oct 12, 2013

I created a very basic program which contains a vector (my vector) that holds 0, 1 and 1. This program compares each element in the vector. If the element after the one currently being compared is equal to it, it outputs "repeat found!" Now this all works perfectly, but my next step was to erase the repeated one. Everything was working up until the delete step. I get a weird error that says "vector iterator not dereferencable" .

// vector::begin/end
#include <iostream>
#include <vector>
using namespace std;
int main () {
vector<int> myvector;

[Code] ....

View 6 Replies View Related

C++ :: Deleting A String Object In Vector?

Sep 21, 2013

Here's my code so far:

case DELETE_TITLE:
std::cout << "Game to remove from list: ";
std::cin.ignore();
getline(std::cin, gameTitle);
for (iter = gameList.begin(); iter != gameList.end(); ++iter) {

[code]....

It deletes the text from the string but not the index it self.

It deletes the text but when I print the list of game titles it has it there blank. I want it to completely remove the object from the vector from where it was deleted

View 1 Replies View Related

C++ :: Dynamically Deleting Items Out Of Vector

Aug 31, 2014

I have the following code in which I wish to dynamically delete items out of a vector based on the condition of the item in the vector.

The below code works but throws the error: "vector iterator not incrementable" at certain times.

It seems like this happens when the last item in the vector get's deleted. How do I solve this problem?

for (std::vector<PhysicsObject*>::iterator it = CurrentBoxes.begin(); it != CurrentBoxes.end();/*it++*/) {
(*it)->CalculatePhysicsOrientation();
(*it)->DrawMe();
glm::vec3* CurrentBoxPosition = (*it)->GetCurrentPosition();
if (CurrentBoxPosition->y < -750.0f) {
it = CurrentBoxes.erase(it);
}
++it;
}

View 9 Replies View Related

C :: Char Array Segmentation Fault

Jun 4, 2013

i want to enter a URL in as a string, and extract just the URL part.

eg: Code: input: URL....

output: URL....

Input: URL....
output: URL....
part of our header file which we cannot edit (the url is always less than 140 characters):

Code:

char url[140];
function i am having problems with
Code: void init_url(char new_url[])
{
/*
This function sets the variable url to new_url and url_size to the number of characters in the url
It also initializes url_error_flag
}

[code]....

whenever i try a URL like the second one above with no '?' i'm getting a segmentation fault error which is becase i'm trying to access an invalid index. i'm not sure what an array is initialized to when i do not explicitly assign it anything, for example

Code:

char values[140] = {0};

i've read it depends on whether it is a global vs local array or something? i know this could all be fixed with simply assigning the array values to 0 but i'm not allowed to edit the header file.

View 11 Replies View Related

C++ :: Read Text File Char By Char By Using Vector Class

Oct 29, 2014

Code:

cout<<"Enter Filename for input e.g(inp1.txt .... inp10.txt):"<<flush;
cin>>filename;
ifstream inpfile;
inpfile.open(filename,ios::in);
if(inpfile.is_open())

[Code] .....

View 8 Replies View Related

C :: Segmentation Fault When Replacing A Char In Array

Jan 25, 2013

This function should replace all instances of a character in a given character array, while returning the amount of characters changed, but I keep getting a segmentation fault at the highlighted area.

I'm only supposed to use pointers so arrays are out of the question, and I don't think we are allowed to use the string.h library as well. How I could avoid something the segmentation fault or ways to fix it?

Code:

int replaceChars(char replace, char find, char *input) { int i, j;
//Finds length
for(i = 0; *(input + (i + 1)) != ''; i++);
int c = 0;
for(j = 0; j <= i; j++) {
if(*(input + j) == find) {
*(input + j) = replace; //Segmentation fault happens here
c++;
} }
return c;
}

View 5 Replies View Related

C :: Appcrash Segmentation Fault Char Inside Struct

Apr 24, 2013

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct info info;

[Code] ....

View 2 Replies View Related

C :: Ciphering Data Segment Of Program

May 31, 2013

I would like to cipher data segmet of my executable say with a simple Caesar Cipher algorithm, i.e. any text should not be readable when executable opened with a hex editor.

It should be something that converts my plain text into a ciphered form at compile time(CPP?), and when executable is being run, should be able to convert ciphered data into human readable text.

I thought meta-programming could be the approach for this. Also, implementing complex algorithms with C pre-processor (CPP) sounds vulnerable (well, depends on one's coding skills let me say)

View 1 Replies View Related

C++ :: Sweep Line Algorithm Applied To Segment Intersection?

Apr 26, 2013

I need updating binary search three. I am working on implementation of Bentley-Ottoman algorithm for finding intersections of line segments in the plane. Code I designed works properly for all, but certain types of triangles. What is happening is that one intersection inside the triangle is never detected due to a fact that segments which intersect in that point never become neighbors in binary search tree.

class segment{
double x1,y1,x2,y2;
int name;

[Code]....

View 1 Replies View Related

C/C++ :: Know That Data Written To Shared Memory Segment In Unix Is Stored Properly

Mar 8, 2012

I am trying to write a client/server application that takes input to an array of structures from the user,stores the data in a shared memory segment and then writes the same to a file when I close the application. How do I get started? And how do I ensure that the server stores the data correctly? Also, the server needs to be a concurrent server that accepts connections from multiple clients.

View 1 Replies View Related

C++ :: How To Concatenate Two Vector Char

Dec 1, 2013

This seamed as a simple thing but i am getting something i did not expect: Example:

Code:
vector<char> StrJoin(SubjSeq.size()+ QuerySeq.size());
cout << StrJoin.size()<<"
"; // size x

StrJoin.insert( StrJoin.begin(), QuerySeq.begin(), QuerySeq.end() );
StrJoin.insert( StrJoin.begin(), SubjSeq.begin(), SubjSeq.end() );

cout << StrJoin.size()<<"
"; // x*2

All structures are vector<char>. when i do the above my characters form Query and Subject are copied in my new vector called StrJoin but the size of that vector is twice the size then it should be.

View 3 Replies View Related

C++ :: How To Make Vector Of Char

Jun 8, 2013

let say

char temp[8][8];

and you want to make vector of this char

vector<????> boardVec;

View 2 Replies View Related

C++ :: Transform TXT File To Char Vector?

Aug 17, 2013

I need to transform a .txt file to a char vector, but how to do it. as much as I could until now been transformed into vector string.

Code:
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;

[Code].....

View 7 Replies View Related

C++ :: String To Multidimensional Char Vector

Feb 3, 2013

I was working on a program which compares sequences of characters, counts the differences between them, and displays them. I had the sequence inputted as a string (into a vector so any number of sequences could be chosen), and then, the way I tried to check the strings for differences, was by converting the string to a (multidimensional) vector of chars:

vector< vector<char> > sequencesC;
for (int a = 0; a < sequenceCount; a++) {
cout << "
Enter sequence " << a+1 <<" name: ";
cin >> sequenceNames[a];
cout << "

[code]....

However, it crashes (as shown above) when I try to set, by a for loop, every char of a multidimensional vector (sequencesC) to the same char of the data vector. Is there any way I can convert the string to a char vector?

View 7 Replies View Related

C/C++ :: Sending Char And Storing It In Vector

Feb 3, 2014

I've got something I'm trying to accomplish, but crashes my program.

I've got my server and client code.

Having the client send a message they type (char Chat[1024]) And the server receiving the chat (char recv_chat[1024]) only to send it to all connected clients again. Which the server sends the recv_chat.

The client receives it (char recv_chat[1024]). This works, and the client gets the right info. However, I'm trying to store it using a vector. I'm sure I've tried any way possible.

Client storing vector pseudo-code:

vector<char*> SaveChat;
int main () {
while (true) {
if (newClientConnected) {

[Code]....

This doesn't work, and crashes my application. I've tried changing the vector to string, const char*, basically anything I can with no avail.

View 8 Replies View Related

C++ :: Print Linked List But As A Vector Of Char

Aug 26, 2013

I was assigned to print a linked list but as a vector of char (I cannot use the normal string type) , this is what I have:

char* List::asString(){
Node* ite = new Node();
ite= first;//ite is like an iterator of the list
for(int i=0; i<sizeOfList; ++i){//sizeOfList is the total of node of the list

[Code] ....

But when I print that, I get a bunch of weird symbols...

View 7 Replies View Related

C++ :: Char Vector - Fixed Size Two Dimension Array

Jun 9, 2013

I want to save the char[8][8] // fixed size 2 dimension array

to a vector

such as

vector<?????> temp;

is there anyway to approach this?

View 4 Replies View Related

C++ :: Comparing Char Array To Char Always Returns True

Dec 23, 2014

I've made a code to check whether or not a save file has been created correctly, but for some reason it always returns this line: readdata[qa]=='1' as true. in which qa is the counter I use in a for loop and readdata is a character array consisting of 50 characters that are either 0, 1 or 2.

this is the entire code:

#include <iostream>
#include <fstream>
#include <string>
using namespace std;

[Code]....

at first is also went wrong at line 22 and also returned that as true, but then I added brackets and it worked.

View 4 Replies View Related

C++ :: Concatenate Two Char Arrays Into Single Char Array?

Sep 29, 2014

I am trying to concatenate two words from a file together. ex: "joe" "bob" into "joe bob". I have provided my function(s) below. I am somehow obtaining the terminal readout below. I have initialized my memory (I have to use dynamic, dont suggest fixing that). I have set up my char arrays (I HAVE TO USE CHAR ARRAYS (c-style string) DONT SUGGEST STRINGS) I know this is a weird way to do this, but it is academic. I am currently stuck. My file will read in to my tempfName and templName and will concatenate correctly into my tempName, but I am unable to correctly get into my (*playerPtr).name.

/* this is my terminal readout
joe bob
<- nothing is put into (*playerPtr).name, why not?
joe bob joe bob
seg fault*/
/****************************************************************/
//This is here to show my struct/playerInit

[Code]....

View 2 Replies View Related

C++ :: Deleting Node In BST

Nov 11, 2014

learning deleting BST node through recursion. In my class my tutor wrote something like this for BST delete node struc:

struct node{
//data
node* root, *left, *right;
}

why not

struct node{
//data
node* *left, *right;
}
node * root;

whats the difference?

View 5 Replies View Related

C# :: Deleting LIST From CSV?

Mar 7, 2014

Basically, I have a LIST that is saved in a CSV file, and I need to remove a particular record after using the search feature (which populates the fields from the CSV file... i.e. ID, Name, etc...).

I am able to get the details that are in the text fields by using a search feature. This is then put in:

logic.remove(tempIndividual)

In class myLogic.cs, then I have this method:

this.individual.Remove(tempIndividual)

Upon debugging, I can see that tempIndividual is populated with the correct data. However, I need to remove this data from the CSV file. Am I on the right track, or totally off? Maybe it is not complete, cause I can't get to the part where it actually removes the data from the CSV, or at least I'm not sure if .Remove is able to do it on its own.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved