Just wondering how you reset a pointer returned from a 'new' command to the first element in an array (currently I'm just using another pointer).
In the code example below the pointer returned gets moved using pointer arithmetic to clear the array. So what would reset the pointer to the first element in the array of characters?
Size = 100; char *data = new char [Size]; // clear array for( int l = 0; l < Size; l++ ) *(data++) = ' '; delete[] data
What I have to do is write a small program in C++ to parse the symbols that are used on 5 different lines of text in each position until position 30 is reached on each line. The goal of the parsing program is to interpret the symbols (characters), if there are any per each position, on the 5 lines of text in order to output the actual data that the group of symbols represents.
My question for is this: Is there anything special from a C++ environment that should go in to something like this outside of using standard stuff like the math associated with the search algorithm that has to happen here? The symbols are located in a file, so I know I have to include "iostream" and a few other headers. But outside of header inclusions and the code necessary to iterate and streamline the search and interpretation process, am I missing anything special that I couldn't otherwise find through simple google searches?
I am not sure why this is happening but I am simply trying to make rounds with my code and have it stop when one of two things, or both, happen.
#include <iostream> #include "Classes.h" #include "RNG.h" #include "select.h" #include "Fitnesschk.h" using namespace std; /*Global Variables************************************/ const int column = 32;
[Code] ....
I've tried resetting and renaming all variables but I don't see any conflict. I tried declaring in different areas but no dice. The other issue I have is that fittest always returns 0 even if the function returns 1. So it infinitely loops. When I go through looking at the variables. the fittest variable never changes even if the function returns 1 and round seems to reset after reproduce is called.
Here is the supporting code.
For Fittracker:
int fittracker(person man[], int row, int column){ for (int y = 0; y < row; y++){ int fit = 0; for (int z = 0; z < column; z++){ if (man[y].data[z] == 1){
So I've actually used rand() happily without any problems so far, but now I faced a problem. I have an AI loop that initialized a random number between 1 and 2 at the beginning, so something like this:
while (condition) { int random = rand()% 1 + 2; if (random == 1) {
[Code] ....
So this doesn't really work since it doesn't actually assign a new random value. I came across srand(time(NULL)), which resets the seed, but I didn't quite get when to use it. Do I have to call it in every cycle of the loop? I'm not completely sure how this works.
I am trying to resize a bmp image by FACTOR times. I got the width resize working correctly but for the height I need to print each row of pixels or 'RGBTRIPLE' FACTOR number of times. I am pretty sure I have the fseek line in the right spot (marked here) I just don't know how many bytes to move it by I tried 1 I though 1 byte past the end would move the pointer to the next line but that did not work. This is for a class so please no code. Here is my code.
I am creating a SpaceShip class, which has arrays for weapon names and damage, and variables for shields power, hull, engine power, and mass. I created two instances of the 'SpaceShip' class, 'ScoutShip', and 'Cruser'. When one of them calls the 'FireWeapons' function, it has the other call the 'TakeDamage' function, but for some reason the 'sheildPower' resets after 'TakeDamage' ends.
#include <iostream> #include <vector> using namespace std; class SpaceShip {
Is there some quick way of resetting the contents of an existing array to 0? Just to be clear, I'm not initializing the array, it already exists, has content and needs to be reset at 0. Is there a faster way than the code below?
I'm trying to move the File Pointer to the end of the file (check.txt) at line-13. But doesn't matter how many times I run the program out put always comes as
O/P: Pos=0 Pos=0
#include <iostream> #include <fstream> #include <ostream> using namespace std; int main () { streampos size; char * memblock;
So for a project I'm working on, I'm using an array and generating it's values randomly but unique. Currently I'm working on a 3X3 array and the generated values are in the range from 1-9. So I wrote a function that will tell me the position of the cell whose value is 9. This is the function I wrote:
Code: void Llogaritje1(int t[3][3],int &i, int &j){ int y,l; for(y=0;y<3;y++){ for(l=0;l<3;l++){ if(t[y][l]==9){ i=y; j=l; break; } }if(t[y][l]==9) break; } }
But it doesn't work on all cells. Seems like at cells t[1][0] and t[2][0] the values that i and j take are 0 0 since when I print them after excecuting the function that's what it returns. I really don't understand why.
I want to get the iterator position after to use find if:
std::list<Texture*>::iterator result = find_if( texturelist.begin(), texturelist.end(), std::bind2nd<CompareTEX>(CompareTEX(),n_tex)); if (result != texturelist.end()) { return // position result }
What I want to do is get all characters in a string up to a certain delimiter, for that I've searched I can do that with:
sscanf getline strok
But what I don't know and haven't found is how to use these functions but to start reading from a certain position in the string. So I need to get the characters up to a comma but after "THIS," so that would be starting in position 5...
How could I do that? I tried using [x] in brackets but then it would just read a character...
I am new to grpahics progamming in/under Borland C. I have included the "graphics.h" header file but i am unable to take input on the screen. If I try to move my cursor to a specified position using gotoxy() function the pointer doesnt moves to the specified location and starts taking input at (1,1) coordinate.
I need to keep a data structure, which has an id, an object pointer and a position. this id is used to randomize things, the object and the position is attached to this id. So which way is better?
Code: struct data { int id; ObjectBase* obj; Vector3 position; }; vector<data> vecData;
I have a character pointer that points to 4000 bytes of valid data. I need to write these valid contents pointed to by this pointer into the file. I am looking for the most optimized way of doing this. I am using the below logic which seems trivial. Any better approach to accomplish the same?
/* length is the number of valid bytes of data */ void parse_contents(const char *data, int length) { int j = 0; char path[1024] = "/tmp/data.xml"; FILE *fp = NULL; fp = fopen(path, "wb");
When we are using RAM DISK - the files are stored on the RAM. From what I understand (and saw many examples) in order to read data from file (the file which locate on the RAM) - I need to use the read function.
Is there a chance to get char* (or any pointer) to the content of the file without using the read function ?
If the file locate on the RAM, it seem that it is like I have a buffer on the RAM (like an array which was dynamic allocated) and in the case of a buffer on the ram -> we can use pointers to the data without reading all the data.
example:
class CDATA { int nValue1; int nValue2; double dValue3; double dValue4; char achBuf[10];
i have two point P1 and P2 where i want to move P1 and P2 with keeping the distance and the position of the P2 relative to P1 i thought that when i keep the distance between the two point that involve keep in the same time the local position of P2 but when tested it does not work initial position of P1=(10.0f, 00.0f, 00.0f) initila position of P2 relative to p1 =(50,10,-8) we can get the global position of p2 ----- final position of P1 =(50,10,-8) final position of P2 in the world space =(40.31,8.06,-6.45) then we calculate the distance before and after we found that there are equal but when we calculate the position of p2 relative to p1 after and before we found that there are not equal.
I try to find charecter position but evey time i run my program it give me 0 position why ? Why in my getChar function give me warning statement with no effect i can not understand this warning where is my mistake.
Code: void getChar(const char* str){ int lenStr = strlen(str); int i = 0; int posCharecter = 0; printf(" %s has %d charecters length ",str,lenStr);
I have been working on a program that records the time it takes the user to complete a maze. The user's time is then recorded and inserted into a linked list of structures based on the time (from quickest time to longest). I wrote some code that does this, but I was wondering if I can make the code more concise/make sense -- like only using two pointers or having less if statements.Here is a struct that are the elements of the linked list (I also have a global variable to keep track of the head of the list:
I want this code to return the value of the bit at position bitIndex. It can be either false or true. The problem is, that it always returns false, even thought I enter 16 as my number, so the 5th bit should be true.
I recently wanted to create a (yet) simple program that simulates a mouse movement.So far I managed to make the program work. It does move the mouse, click when expected but the problem is the location it does click at.Here's my code:
#include <Windows.h> #include <stdio.h> int leftclick (DWORD x, DWORD y); int main(){
[code]......
The problem now is: I want the program (for testing purposes) to click at (1920, 1080) and (100, 100) afterwards. Now it does click within a specific range. When I use GetCursorPos to retreive the cursors position it differs quite a bit from where I expected the click to be.
a second question I have is: When I declare the following flag (in the code above) the program does use relative coordinates even though it shouldn't.