C++ :: Crash When Initializing Indices Array
Nov 26, 2012
Why I get a crash when initializing the indices array below (bottom)-
Code:
struct TerrainGroupData {
TerrainGroupData(){};
TerrainGroupData(Ogre::Vector3 ** iVertices, unsigned long ** iIndices, size_t* iFaceNum, size_t* iVertNum) {
vertices = iVertices;
indices = iIndices;
[Code] ...
View 9 Replies
ADVERTISEMENT
Feb 13, 2014
Whats the fastest lock to use when a few indices in an array is to be locked?
Example:
Code:
some global array = {0,1,2,3,4,5,6,7,8,9}
...
//omp section
one processor needs to lock indices 3,5,6
for(i:loop through 3,5,6)
which lock on :
array[i]
View 2 Replies
View Related
Feb 20, 2015
I need it to search a dynamic array which I build from an input file. When it finds the user-input string, I want it to store the line number, and continue searching, and record all lines that contain the user-input string.
Here is a link to my complete main.cpp, header file, and implementation file. The function I am having trouble with is "Bagger::lineSearch"
[URL] ....
View 2 Replies
View Related
Nov 6, 2012
I have a function such that one of its parameters is a 2D array of type int. The parameter is defined as follows:
[code]
int topoGraph [][MAX_VERTICES]
[code]
However, the following code snippet from the body of the function crashes at the specified line:
Code :
if( counter >= 4 && !adjMatrixAlreadySet) {
if( edgeCost == 10 ) {
topoGraph[srcVertex][dstVertex] = 1; <<<<<---------- The point of crash
}
else if( edgeCost == 100000 )//restricted link {
topoGraph[srcVertex][dstVertex] = edgeCost;
[code]....
It seems like there is an undefined behaviour at the specified point of crash since it crashes with different values of srcVertex and dstVertex each time I run it.
What might be the reason for this crash ?
View 4 Replies
View Related
May 10, 2013
I am new to C. I've been trying to use C to code some statistical functions originally coded in R. I've encountered an interesting phenomenon. In the function foo1, I declared the array v1v2b using an actual value 1999000. The function runs fine when I call it in R.
Code:
void foo1(double *x, double *y, int *nsamp){
int i, j, k, oper=2, l;
double* v1v2=malloc(sizeof(double)*((*nsamp)*(*nsamp-1)/2 + 1));
outer_pos(x, y, nsamp, &v1v2[0]);
double v1v2b[1999000]; //<-------HERE
for(i=1; i<= 1999000]; i++){
v1v2b[i-1]=1;
} }
However, in foo2, I first create an integer variable called index, and store the value 1999000 in it. I then use it to initialize the same array. When I tried calling this function in R, it either led to a stack overflow error, or completely crashed R.
Code:
void foo2(double *x, double *y, int *nsamp){
int i, j, k, oper=2, l;
double* v1v2=malloc(sizeof(double)*((*nsamp)*(*nsamp-1)/2 + 1));
[Code] .....
View 9 Replies
View Related
Mar 6, 2015
I am making a tictactoe program that requires me to have a 3 by 3 two dimensional array of integers, in which the constructor should initialize the empty board to all zeroes. The program complies, but it keeps outputting garbage values and i'm not entirely sure why, My print function isn't complete yet, since I want to print out the array in a tic tac toe format, but i'm more concerned with why it's printing garbage values, here is my code:
Code:
// header file
#include <iostream>
#include <array>
[Code] ....
View 7 Replies
View Related
Feb 25, 2014
How to initialize this array of structures in my code
struct CustomerAddress; {
string street;
string city;
string state;
int zip;
[Code] ....
I am going to be using a boolean variable to mark whether or not a specific field has had data entered into it. I figure the best way to do that is to initialize all the elements of the structures to 0. However, with strings and with the nested structure, I'm not sure how to do this.
View 6 Replies
View Related
Jun 28, 2012
I'm writing a program that will display 70 random temperatures, using an array that stores each number. They are going to be divided into weeks (7 temperatThe loures per line), and before displaying each of the seven temperatures, I want to first display the week #. The loops I'm using work, however the variable 'i' always first displays 2, and then counts. The loop initializes it to 0, so I don't know why it's immediately obtaining a value of two. The code is posted below.
Code:
static void DisplayTemps(int[] a)
{
Console.WriteLine("Su M T W Th F S");
for (int i = 0; i < a.Length / 7; i++)
{
Console.Write("Week {0} ", i);
for (int j=(i * 7); j < a.Length; j++)
[Code] .....
View 1 Replies
View Related
Jul 14, 2014
I have some struct which contains: void *elems (basically a pointer to an array of contiguous memory).
I want to use bsearch to return a pointer, and then somehow figure out where in the array that value is. Having a pointer in this case isn't enough, I need to know what the index is. I've tried a number of things:
int index;
void *value = bsearch(key, start_ptr, cv->count, cv->elemsz, cmp);
index = &value - &start_ptr;
return index; [
Replacing the second line with:
// in the first instance
index = (char*) value - (char*) start_ptr;
// in other instances...
index = ((char*) value - start_ptr))/cv->elemsz)
But nothing works.
View 6 Replies
View Related
Aug 1, 2013
How to initialize double pointer array..?
int (**aLines)[2];
View 3 Replies
View Related
Dec 29, 2013
is it possible to create a dynamic array with all entries in it equal to 0?
int** adjMatrix;
adjMatrix= new int*[numOfVertices];
for(int i=0; i<numOfVertices; i++){
adjMatrix[i]=new int[numOfVertices];
}
View 1 Replies
View Related
Jul 31, 2013
Want to initialize a local one dimensional array. How can I do the same without a loop?
Found from some links that
int iArrayValue[25]={0};
will initialize all the elements to ZERO. Is it?
If yes then can we write below code to initialize the elements to a non-ZERO value?
int iArrayValue[25]={4};
Do we have some other way to initialize an array to a non-ZERO value? Memset can initialize the element to ZERO.
View 7 Replies
View Related
Nov 15, 2014
In one of my programs I have a 3x3 array of string that I use to display the outcome to rock, paper, scissors, and another 1x3 used for a number guessing game. I have the arrays declared in the header file as follows:
//Games.h
std::string rpsOutcome[3][3];
std::string hiLoOutcome[3];
and then initialized them in the cpp file:
//Games.cpp
string rpsOutcome[3][3] {
//row 1
{ "Both of you picked rock, you tied. Try again",
"You picked rock, the computer picked paper, you lose",
[code]....
From what I've read, Im pretty sure thats how your supposed to initialize multidimensional arrays (using the nested braces), but when I build the project, I get the following error:
123456789101112
1
1> RockPaperScissors.cpp
1> Games.cpp
1>c:userswuubbgoogle drivevisual studio projectsgamesgamesgames.cpp(75): error C2374: 'games::rpsOutcome' : redefinition; multiple initialization
[Code] .....
View 4 Replies
View Related
Mar 8, 2015
I am making a tic tac toe program in which they are asking me to have a 3x3 2 dimensional array of integers and have the constructor initialize the empty board to all zeros. They also want me to place a 1 or 2 in each empty board space denoting the place where player 1 or player 2 would move The problem I'm having is, my code initializes the board to all zeros for each element of the array, and prints it out just fine, but I can't figure out how to re-initialize the values in the array to show where each player moves on the board... I was thinking about having a default constructor that has each value set to zero, and then use a setGame function that can change the values on the board to one or two depending on where the player moves....but I don't know if that's possible.....
here is my code
Code:
// header file
#include <iostream>
#include <array>
class tictac {
public:
tictac(int);
[code]....
View 8 Replies
View Related
Nov 24, 2014
I'm learning OpenGL using the C API and some of the functions' argument types have proven a bit challenging to me.
One example is the function Code: glShaderSource(GLuint shader, GLsizei count, GLchar const** string, GLint const* length); It resides in foo() which receives a vector "data" from elsewhere Code: void foo(std::vector<std::pair<GLenum, GLchar const*>> const& data); To pass the pair's second element to glShaderSource's third argument, I do the following:
Code:
GLchar const* const source[] = {data[0].second};
glShaderSource(..., ..., source, ...);
Now I have two questions regarding this:
1. Can I initialize a char const** via initialization list, the way I do a char const*?
Code:
// this works
std::vector<std::pair<GLenum, GLchar const*>> const shader_sources = {
{GL_VERTEX_SHADER, "sourcecode"},
{GL_FRAGMENT_SHADER, "sourcecode"}
};
// but is this possible?
std::vector<std::pair<GLenum, GLchar const**>> = { ??? };
2. Is there an alternative to creating a temporary GLchar**, even though that's specifically what the function wants?
View 2 Replies
View Related
Oct 23, 2013
Here are the steps to this program:
1. Declare an array that will hold 3000 numbers
2. Initialize this array by assigning a random number to each element in the array
3. Traverse the array, modifying the current contents of each element in the array so that each value now lies between -3000 and 3000 inclusive
4. Traverse the array to compute the average value of all elements
I have never worked with arrays before and am lost!
View 2 Replies
View Related
Nov 7, 2014
InitializeNArray<4, bool, NARRAY>()(narray, {1,2,3,2}, true);
is supposed to initialize a 4-dimensional std::array a with a[1][2][3][2] = true.
The commented-out line, which is the desired recursion, does not compile for some reason, and the problem third parameter cannot be deduced. So I placed some temporary lines to work in the special case only. Howw to make that recursion work?
#include <iostream>
#include <array>
#include <vector>
#include <memory>
template <typename, int...> struct NArray;
[Code] ....
Incidentally, this is a sub-problem within the task of initializing more generally with
template <typename T, int... N, typename... ARGS>
typename NArray<T, N...>::type NDimensionalArray (const T& value, ARGS&&... args)
Once this subproblem is fixed, then the bigger task is fixed too.
View 7 Replies
View Related
Apr 28, 2013
I want to use this array as part of my class. I have tried several different angles trying to get it to work but with out success. I have been checking to see if it works by simply using "cout << dayName[3];" It is printing nothing at all. What is the proper way to initialize this array of strings?
First I tried this:
const string dayName[] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
then I tried this:
const string dayName[7];
dayName[0] = "Sunday";
dayName[1] = "Monday";
dayName[2] ="Tuesday";
dayName[3] ="Wednesday";
dayName[4] ="Thursday";
dayName[5] ="Friday";
dayName[6] ="Saturday";
My implemetation file code and my header file code is here (header first):
//dayType.h, the specification file for the class dayType
#include <iostream>
#include <string>
using namespace std;
class dayType{
[Code] .....
View 4 Replies
View Related
Mar 20, 2015
I am not getting any error below
--------
#include <iostream>
using namespace std;
void main()
{
char sqr[3];
sqr[0] = '1';
sqr[1] = '1';
cout << sqr[0] << sqr[1];
while (1);
}------------
but if I move my char type array before main , I get error l
----------------------------
#include <iostream>
using namespace std;
char sqr[3];
sqr[0] = '1';
sqr[1] = '1';
void main()
{
cout << sqr[0] << sqr[1];
while (1);
}
-------------------
View 8 Replies
View Related
Jul 6, 2014
I have an array of bone parent indices (as intgers), where root bone is tagged as -1, bone can have only one parent. At some point i need to traverse thru all children of some arbitrary bone (leaving others untouched) but this seems tough to do with this setup.
I cannot come up with algorithm to create linked list like hierarchy from this , with old DX9 API in their animation system we have structure like this:
struct D3DXFRAME { // bone
... // some irrelevant data members
D3DXFRAME* pFrameSibling;
D3DXFRAME* pFrameFirstChild;
};
Where I can simply use recursion to achieve what I want.
View 6 Replies
View Related
Jan 16, 2014
whats wrong with this code, I'm trying to parse a .js file and replace all the ";" with "; " i.e add a new line after each ";". So I load the file into a char[] buffer then assign a string to this contents of this buffer. Then loop char by char through using an iterator and check for a ";", if found use replace. So int i gets to about 85898 then crashes with unknown error, 'i' should reach about 175653. It does work up till it crashes. And, is this not a simpler way to load a file into a buffer, there is in C.
Code:
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <stdlib.h>
int main()
[code]....
View 8 Replies
View Related
Jul 16, 2013
Notes: Im Using SDL, Im using Codeblocks to code
Ive narrowed down my crashing problem ( using printf's ) to a malloc call I had to use printf's because when i ran the program in Codeblocks debugging mode, it did not crash and ran fine, but when i ran it normally, it would crash, giving me this error:
fatal signal segmentation fault (sdl parachute deployed)
Inside my code, I created a malloce function that checks malloc for me ( so i dont have to do it )
( general.h )
void* malloce ( size_t size )
{
printf ( "start malloce %i
", size );
[Code]....
funny thing is that i called this malloce function about 20 times before it hits this part of the code, it is unknown behavior to me!
View 10 Replies
View Related
Jul 5, 2012
I have a question about allocating 2MB memory then filling it...
@ Platform:
=> DOS, and application is compiled/linked via Watcom C + DOS32/A (...memory model is "flat" mode)
@ phenomenon:
1. I allocate 2M memory by calloc() function. Then I got "!NULL" and it means allocating 2MB memory is ok( right ? )
2. then I tried to "fill" this 2MB memory by for loop(one byte by one byte) like below:
for( DWORD i=0; i<0x200000; i++) {
*((BYTE *)(A[0].B[0]->C) + i ) = 0x5A; // C is 4-byte address value
}
here :
* DWORD means "unsigned long(4-byte)" and 0x200000 means "2MByte"
* in actual case the value of pointer(to allocated memory) is 3019AF3C(~768MB) <- running in flat mode...
3. after filling this range of memory(2MB) the application crashed...
@ my observations:
1. if allocating 2MB and no fill(no write data to memory) => OK
2. if allocating 2MB and just fill the former 32 bytes => OK
3. if allocating 4KB and fill all => OK
my question is: why can't I filling this 2M memory totally "even memory allocation succeeds" ?
View 5 Replies
View Related
Oct 24, 2014
This function is apparently causing infinite recursion, but I have no clue what's causing it:
Code:
int pow( int base, int exp ) { int somevariable = pow(base,exp-1);
if (exp == 0) {
return 1;
}
else {
return base * pow(base,exp-1);
}
}
View 10 Replies
View Related
Feb 17, 2014
cant write to binary file
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int number;
} something;
void main() {
int numbers[10]={1,2,3,4,5,6,7,8,10,12};
[Code] .....
View 2 Replies
View Related
Jun 26, 2014
On a project I'm working on, I need to update many QLabels very quickly. Each label needs to be updated at about 20 to 50 hertz and there can be over 50 labels at any given time. The problem I'm having is after running the program for about a minute, the labels freeze and the whole program crashes about 10 seconds later. If I comment out the setText() and setNum() calls and reroute the outputs to the console, it runs fine and never crashes. Why does calling SetText() and setNum() so quickly cause the program to crash and how can I prevent this?
View 5 Replies
View Related