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.
Example; 0 to 0.2 = 0 0.3 to 0.5 = 0.5 0.6-0.9 = 1
What's the formula for C++?
I found a way to do it in math but I want to know what I'd have to put in C++. It's (x*2+.5)remove decimal numbers and divide by 2. What do I put in place of "remove decimal"?
For ex; x = 8.4 using (x*2+.5)remove decimal then divide by 2. 8.4 * 2 = 16.8 16.8 + .5 = 17.3 17.3 - decimal = 17 17/2 = 8.5
was making a somewhat of a Binary to Hex convertor but only 10/15 cases work and the non working are in the middle; 0010, 0011, 0100, 0101, 0110, 0111;;
// Test Code.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> #include <cmath> #include <conio.h> using namespace std; int main(void) {int A; cout << "Enter the binary starting with the MSB
In short: 1. Input is an N x N grid with a non-negative integer in each cell. 2. We can move from one cell to any of its adjacent cell in all four directions. 3. The 'cost' needed to move from one cell to another is the positive difference of their values. 4. We have to find the minimum cost such that we can visit atleast half of the cells with that cost;
I am not being able to think of any solution that runs in time O(N2) or better (N2 because of the size of N, any algorithm worse than it will not run within the time limit) for this problem.
So I need a hint on how to solve this problem optimally.
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 )
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.
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" ?
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?
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));
I have a class which dynamically allocates memory for three data arrays, and as such in the destructor I told it to delete those data arrays.
However, when I've created a new class, and inherited the previous class - it will always crash AFTER running the program, unless I don't have the previous destructor present.
my program crash when it try to assign the return value of the function to the local value. extract function does return correct value, but it just crash when done executing.
I need to do an equivalent of kill -11 <pid>(which is in unix) in windows.
I need to crash a process with SEGV so that it would dump core in windows. Is there any tool by which we can do this . Also is there any sample code through which we can achieve this .
In windows we have taskill which only terminates a process , but is unable to send a signal like SEGV to the process upon which it would terminate and dump core .
I have a class 'A' which is almost perfect for my needs. Class 'B' uses class 'A' I've now designed Class 'C' and Class 'D' and noticed that there is a good chunk of code in class 'B', 'C' and 'D' for using Class 'A' is duplicated. I've separated out this code in specific, standalone functions in each of the classes. Now I'm wondering where this code should go. At the moment, the functions are duplicated in the three calling classes (B, C and D). Placing the functions into class 'A' would break the single responsibility principle. Inheritance to add functionality would likely break both SRP and LSP. The one that seems that it may work is composition.
However, Is designing a complete class just for a few functions over kill?
Would it be valid for classes 'B', 'C' and 'D' to access both the new class 'E' (which would depend on A) and the old class 'A' (which would have to be the same instance as the instance in the new class 'E'), or should the new class 'E' provide sufficient functionality so that Classes B, C and D don't need to access Class A directly? It would seem that its then an incomplete interface of the original object with additional functionality (ie, incompatible) Or should I do it a completely different way?
I am making a game and want to make an updater that grabs the source code from a page on the web. Can this use things that are available to all platforms? It could just be something that grabs the text from the page and executing it (maybe using something like Python's exec() command ?) BTW I'm using mac