C/C++ :: Resetting File Pointer Position

May 10, 2013

it will search the whole file once then i cant get it to reset without restart the program.

cin >> paycode;  
while(paycode!=0) {
  while(!infile.eof()) {
    infile >> search;
    infile.ignore(1);

[Code] .....

View 1 Replies


ADVERTISEMENT

C++ :: Resetting Pointer Using New

Apr 23, 2014

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

View 13 Replies View Related

Visual C++ :: Reading Character Symbols On Lines Of Text Position By Position?

Mar 4, 2013

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?

View 6 Replies View Related

C/C++ :: Why Counter Keep Resetting To Zero

Feb 17, 2015

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){

[Code] ....

View 10 Replies View Related

C++ :: Using Rand Function And Resetting Seed?

Nov 9, 2014

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.

View 2 Replies View Related

C :: Move File Position Indicator To Next Line

Jul 27, 2014

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.

Code:
#include <stdio.h>
#include <stdlib.h>
#include "bmp.h"
[code]....

View 3 Replies View Related

C++ :: Space Ship - Class Variable Resetting

Apr 9, 2014

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 {

[Code] ....

View 3 Replies View Related

C++ :: Resetting Board On TicTacToe In Order To Play Again

May 25, 2014

How to reset the board in order to play again without spots already taken.

#include <iostream>
#include<cstdlib>
#include<ctime>
using namespace std;

char location[10] = {'0','1','2','3','4','5','6','7','8','9'};
int displayMenu(int &player, int &win);

[Code] .....

View 1 Replies View Related

Visual C++ :: Resetting Contents Of Existing Array To 0?

Apr 13, 2015

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?

Code:
for(i=0;i<100;i++)myarray[i]=0;

View 6 Replies View Related

C/C++ :: File Pointer Not Moving To The End Of File

Oct 15, 2014

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;

[Code] ....

View 3 Replies View Related

C++ :: Map - How To Get The Key Of Element By Position

Sep 21, 2013

I have a "fairly" large, std::map. Is there a way, to get the key of an element, by position? E.g., something like,

map.at(i).getkey

View 5 Replies View Related

C :: Array Finding Position Of A Value?

Dec 24, 2013

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.

View 4 Replies View Related

C++ :: Get Iterator Position After Find If

Jan 25, 2013

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
}

View 5 Replies View Related

C++ :: Partial Tokenization From A Certain Position

Mar 14, 2013

I have a string like:

char *origin = "THIS, IS, SPARTA!"

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...

View 5 Replies View Related

C/C++ :: How To Take Input From Particular Position Using Graphics

Feb 26, 2013

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.

View 1 Replies View Related

C++ :: ID Followed By Object Identifier And Position?

Jun 4, 2014

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;

or

map<int, pair<ObjectBase *, Vector3>> mapData;

View 4 Replies View Related

C++ ::  Writing Pointer Contents Into File

Apr 15, 2014

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");

[Code] ....

View 2 Replies View Related

C++ :: RAM Disk And Pointer To Content In File

Mar 3, 2014

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];

[Code] .....

View 2 Replies View Related

C++ :: Relation Between Local Position And Distance

Feb 21, 2014

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.

how i can keep the local position and distance ?

View 14 Replies View Related

C++ :: How To Display Item At Specific Tab Position

Nov 23, 2013

I used VB6 before to output file.

I set my output to file to tab(20) or tab(45) respectively.

In C++, how do I do this?

View 4 Replies View Related

C :: Find Character Position - Output 0

Jul 8, 2014

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);

[Code] .....

View 2 Replies View Related

C :: Linked List Insertion At A Particular Position

Mar 4, 2014

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:

Code:

//stores player's best time.
struct PlayerTime {
char name[MAX_STR_LEN];
float seconds;
struct PlayerTime* next;

[Code]....

View 4 Replies View Related

C :: Code To Return Value Of Bit At Position Bit Index

Jan 10, 2015

Here's my code

bitIndex = 5;

Code:

bool getBS(PBitSet _this, int bitIndex) {
if(_this->bits & (1 >> bitIndex))
return true;
else
return false;}

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.

0000|0000 = 0
0001|0000 = 16

View 10 Replies View Related

C++ :: How To Find Coordinates Of Cursor Position

Feb 4, 2014

I have studied function,array,stuctures,flow of control(XI class cbse syllabus). Now I want to know how to find coordinates of cursor position in c++.

View 2 Replies View Related

C++ ::  SendInput - Cursor Position Wrong

May 12, 2013

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.

input.mi.dwFlags = MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;

Where as it works out well when I add a MOUSEEVENTF_MOVE to it.I couldn't find any solution to this in Microsoft MSDN or any other website.

View 2 Replies View Related

C++ :: How To Find Position Of Certain Character In String

Jan 11, 2013

I need to find position of certain character in string, so i made a function but it doesn't do what i thought it would.

Consider this string:

std::string line = "<foo> <foo> <foo> <foo> <foo>"

I need to find position of a third '>' character so i can get:

std::string other = "<foo> <foo> <foo>";

This is my function that fails:

std::size_t find_third(const std::string& line) {
std::size_t pos = 0u;
for(std::size_t i = 0; i < 3u; ++i) {
std::string tmp = line.substr(pos);
pos = tmp.find_first_of('>');
} return pos;
}

View 6 Replies View Related







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