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


ADVERTISEMENT

C++ :: Class Which Loads Bitmap Image Into One Dimension Char Array

Aug 27, 2013

I am writing a class which loads a bitmap image into a one dimension char* array.

This class has methods to allow for resampling and cropping the image before saving the bitmap image. It works perfectly for all images in which the width is divisible by 4. However when the width is not divisible by 4 the resulting bitmap is all mixed up.

I have spent much of the day googling this problem but to no avail. I know it is a problem with making sure the scanlines are DWORD aligned, and I believe I have done that correctly. I suspect that the problem is that I need to take the padding into account during the crop for loops but am lost to how to do this.

BTW: Coding on Linux using GCC

The following code is a cut down version from my bitmap class. I have removed methods which are not needed to make reading a little easier.

#include "BMP.h"
// FIXME (nikki#1#): Portrait bug on images of specific sizes
// TODO (nikki#1#): Memory leak checks
// THIS METHOD WRITES A BITMAP FILE FROM THE CHAR ARRAY .
bool BMP::saveBMP(string fileName, string *err) {
FILE *filePtr;

[Code]...

View 2 Replies View Related

C++ :: How To Create Unordered Map Of Fixed Size Vectors

Sep 19, 2013

how to create an unordered map of fixed size vectors?

Code:

unordered_map<string, vector<int>> x;

x["mumb 5"][7] = 65; // this does not work since my vector size is not set.

View 7 Replies View Related

C++ :: Size Of Char Array - Comparing Name To Another One (Pointer)

Jul 13, 2013

I have function that looks like this myfoo(char* Name) Now i want to compare this name to another one . But the another name is a pointer . This my code :

bool Tribe::RemoveSurvavior(char *H_Name) {
const char *p;
p=SurpointArr[i]->GetSurvivor_Name();
}

I need to compare if p is same as H_Name.

Mine is do it with for on each element but when i use sizeof it gives me size of char and not real size of the name.

View 6 Replies View Related

C++ :: Char Array Size - Undefined Until User Input

Apr 27, 2014

So I'm trying to make a program, Which has nothing to do with the topic. But I ran into a problem.

I need to get a char array size of 6 doing:

char myChar[6];

but the size (6) is undefined until user input.

So I need to do char myChar[var]; (Var being 6 for now).

When I do:
char myChar[6];
It works!!!

But when I do:
int val = 6;
char myChar[val];
It doesn't work.

View 3 Replies View Related

C++ :: Output Increases With Dynamic Char Array Size?

Jul 22, 2012

I've been in a strange problem. Im in need to have a dynamic character size, but that increases the outputsize of my program by almost 50kb. (while the program was 11kb previously).

Example:

Char One[7000]; (11kb output)

int Z = 7000;
Char Two[Z];

View 7 Replies View Related

C++ :: Function That Declares Array Of Char Of A Size Of 350000 Elements

Jun 5, 2014

I'm working on a piece of code written long time ago. Without getting in the details or too much context here, there is a function that declares an array of char of a size of 350,000 elements, in order to fill it (using a pointer) with the list of all running processes on the machine (using "ps -ejf" on a Linux box).

The size of the char array has been changed from 40,000 to 350,000 sometime along the years, probably because of a lack of space required.

What kind on data structure / storage would you use to store the running processes in order to eventually search for a value in it?

View 2 Replies View Related

C++ :: Initialize Size Of Vector Array Position And Color?

Feb 3, 2015

Getting back into programming after a few years off and a bit rusty.

My question is: Is this going to initialize the size of the vector array's position and color properly?

#include <GLFW/glfw3.h>
#include <vector>
class TerrainClass {
private:
struct VertexType {
std::vector<float> position[3];

[Code]...

View 6 Replies View Related

C++ :: Using Array Of Size That Will Be Determined By User - Implementing Vector

Oct 20, 2013

I am trying to use an array of a size that will be determined by the user, therefore I must use a vector, right?

In class I was told that this is how I call a vector:

vector <int> x;

Is the vector called vector? Is it called x?

Can I do this?

for(int i=0;i<=10;i++)
{
cout<<x[i];
}

Some basic ways of implementing a vector? How it works or how I can do anything with it.

View 2 Replies View Related

C++ :: Passing Fixed Character Array Into Binary File?

Apr 19, 2014

all i want to do is to read a fixed char array sized 4 from user and pass it to Binary File then Print Encrypted content from the the File to the console screen .. but it seems it prints the same input every time .. and i tried everything .. it works fine with integers and strings .. but when it come to char array nothing ..

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

[Code].....

View 6 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++ :: Dynamically Allocating One Dimension Of 3D Array?

Jun 14, 2013

I am trying to figure out the syntax to dynamically allocate a single dimension of a triple dimensional array. Basically i have a 2D array of structs. but each struct is an array (basically rows of the information). The rows of this structure need to be allocated dynamically, but the height and width of the overarching structure are static.

Basically: Struct * ts_FieldInfo[100][100] = new Struct[Class.returndataitems()];

View 2 Replies View Related

C++ :: Initializing Local One Dimension Array?

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

C++ :: Copy Middle Of 2 Dimension Array Into Another Array

Aug 14, 2013

I want to copy the middle of 2dim array into another array. who knows how i can do it. for example I have:

int A[4][2] = {{1, 2} ,{5, 6} , {7, 8} , {3, 4} };

copy the second and third rows into another array to have the following array:

int B[4][2] = {{null, null} ,{5, 6} , {7, 8} , {null, null} };

View 2 Replies View Related

C/C++ :: Store C-style String In Third Dimension Of 3D Array

Jan 24, 2015

I am trying to read in data from a text file and store it inside a 3D array. The text file looks like this:
bar bell orange
bell bell 7
lemon cherry cherry

I can read in the data fine, but how to store it inside the array. My array looks like : [ Char slotMachine[10][3][8]; ] T

he dimensions are Row, Column, and symbol. There are 10 rows and 3 columns inside the file. The third dimension is supposed to hold the symbols as a C-style string.

This is what I have been trying:

char symbol[8];
int rowIndex = 0, colIndex = 0;
While(fin.good()){
fin >> symbol;
slotMachine[rowIndex][colIndex][] = symbol;
rowIndex++;
colIndex++;
}

I know that i'm not storing the symbol right. How to correctly store it inside the third dimension.

View 4 Replies View Related

C++ :: Create Main Function With One Dimension Dynamic Array With Float Data Type

Dec 4, 2013

I need to create a main function with a one dimension dynamic array with float data type. The total number of array elements must be controlled by a user input from the keyboard. Test data is three different lengths 3,6,9 of the array. The lengths have to be set up at run time from users input. I understand how to create dynamic array but not where the user inputs the length of the array. How would I implement this?

View 6 Replies View Related

C++ :: What Is Default Size Of STL Vector

Jan 30, 2012

For example, I have an empty vector of integer. If I keep calling push_back on vector, is it going to be out of memory?

View 8 Replies View Related

C/C++ :: Size Of Class When Char Member Added

May 25, 2014

Why is the size of an empty class 1? Why is the class still one when I add a char member to the class?//using turbo c++ 3.0, yes I know I'm using a very old c++ compiler and software

View 3 Replies View Related

C++ :: Vector Reaching Its Maximum Size

Feb 5, 2014

My program enters the size of the vector from the user and then creates a vector of vectors (lets say SIZE1). In addition the user enters the number of vector of vectors he needs (lets say SIZE2) as follows:

class Vectors {
// member functions goes here
private
vector<vector<int>> vectors;
vector<int>::iterator it;

[Code] .....

With a few calculations and insertions to my vector (vector of vectors)... the program works fine and gives me the results...

However, with huge calculations and insertions the program stops working and gives me this message

"Unhandled exception at at 0x770DC41F in Test.exe: Microsoft C++ exception:std:bad_alloc at memory location 0x001CEADC"

Thus, it seems that the vector reached it's maximum size... I tried to use reserve() but did not work

I read that "By default, when you run a 64-bit managed application on a 64-bit Windows operating system, you can create an object of no more than 2 gigabytes (GB). However, in the .NET Framework 4.5, you can increase this limit"

What do you think would be the best option for me to do (note my program is very long and complex)(I'm currently using Microsoft Visual Studio 2012 32Win application):

1. convert my program to the .NET Framework (C++)

2. convert my program to C# in case c#

3. do any settings on my computer (my workstation has a 3.6GHZ xion processor with 32RAM

4. convert to another version of C++ that does not have any restriction on the size of the array (if available)

Please note that I never worked neither with the .NET framework nor C#

View 3 Replies View Related

C++ :: Memory Size Of Vector Elements

Apr 9, 2014

I had a question about memory allocation/how iterators work for a std::vector<foo> of a user defined class 'foo'. Say foo contains variables of variable size, so that each member of the std::vector<foo> does not require the same amount of memory space.

Does c++ allocate the same amount of memory for each element, equal to the amount of memory required for the largest element? Or does it use some sort of array of pointers pointing to the location of each element in the vector to make the iterator work? Or does it use some other method? I am wondering because I wrote a code which reads data from a binary files and stores most of it in std::vectors.

The code seems to be using significantly more memory than the sum of the size of all the binary files, and I am using vectors made up of the datatype within the binary files (float). So I was wondering if internally the code was allocating space for each vector element which is the size of the largest element as a way to handle indexing/iterators. I ran my code through a memory leak checker and it found no errors.

View 16 Replies View Related

C++ :: How To Account For A Size 0 Vector In Function

Dec 16, 2013

I'm trying to do is write a program that fits to a separate test program. The test program provides different size vectors that my function should try and binary search. If the element is found, the function should return 1, and if the element is not found, it returns -1.

Here is the code:

int binSearch(const vector<double> & data, int elem, int & comps) { {
int beg=data[0];
int end=data[data.size()-1];
int mid=(end+beg)/2;

[Code] ......

The problem is that one of the vectors my function is supposed to binary search is a vector of size 0. I tried to throw in an if statement that would return -1 if the size was == 0, but then the program never fully completed and just kept running. So, how can I account for a size 0 vector in my function?

View 2 Replies View Related

C++ :: Passing Vector To A Function - Getting Negative Length And Size

May 22, 2013

I am writing a raytracer, and currently I'm working on creating a bounding volume hierarchy to accelerate the process. To do this, I am first creating a vector that holds each of the objects in the scene, and passing this vector to the constructor for my BVH.

Code:
//in header
BVH_Node* bvh;
//in main raytrace function

[Code] .....

I am testing a scene that has only 2 objects, and so it goes to the size == 2 check. The first time it hits makeLeaf(), I segfault. I've used both gdb and valgrind, and of course it's a memory mapping error. gdb's backtrace tells me that the length of the vector I've passed in is -805305610 and the capacity is -21, and that it is inside my makeLeaf() function that the error occurs.

Here's the function:

Code:
BVH_Node* BVH_Node::makeLeaf(GeomObj* v){
BVH_Node* node;
node->obj = v;
node->isObj = true;
return node;
}

The segfault happens at
Code: node->obj = v;
If I run my raytracer without a BVH, the objList works perfectly.

View 8 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







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