C++ :: Dynamically Changing Array Elements Inside Of Structures?

Feb 1, 2015

I have run across what I believe to be a syntax problem which I don't understand. I have a structure with two character array and I need to be able to change the size of those array dynamically. I have to use character arrays and I think the dot notation. I am not sure if I can use arrow notation. I can not do this problem using strings and vectors.

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

[Code]....

View 4 Replies


ADVERTISEMENT

C++ :: Accessing Elements Of Array Dynamically

Jul 26, 2014

I want to access the elements of my array dynamically. So far I've only figured out how to do this manually. if I tried it like this my code would work but there should be a better way right?

View 10 Replies View Related

C++ :: How To Delete Elements In Array Of Structures

Apr 4, 2013

Any example to delete an element in an array of structure?Is it same as deleting an element in an array.ie like this....???

// to delete an element in an array
#include<iostream.h>
#include<conio.h> // for clrscr() and getch()
void main() {
clrscr();
int a[50],n,t,index,i;

[Code] .....

View 1 Replies View Related

C :: Fastest Way Of Changing Elements In Array Of Characters For Encode

Feb 15, 2014

I am wonder what is the fastest way of changing elements in array of characters for encode purpose, here is simple example presenting an idea:

Code:

char *a = "123456789":
char b[] = "ABCDEFGHI";
int 1;
for (i=0;i<strlen(a);i++) {

b[i] = a[i];
}

Is this approach better or worse than bit manipulation ?

View 4 Replies View Related

C/C++ :: Displaying Array Elements Inside Struct

Feb 13, 2015

How can I display the elements of an array inside struct something like this

struct ABC {
double a[3];}
void show( const ABC & x );
ABC x{18, 'W', { 1.1, 2.2, 3.3 }};
show(x); would output {18, ‘W’, {1.1, 2.2, 3.3}}

View 10 Replies View Related

C++ :: Dynamically Changing Property Of A Class?

May 27, 2013

Working on a console application and I am trying to figure out a way that allows users to enter an object property along with a value. For example

class Box{
public:
int height;
int width;
int length;

[Code] .....

For example if a user inputs "height" for Name and "13" as value I would like to find a way to change ab's height to 13. I want to make this work so that one can add another class and get the same functionality.

I tried looking online and I think maps are a way to do this and I tried doing that but I don't know how to proceed after/what code to write that would allow me to change it.

Note: I can't use if else statements or hardcoding to match the input to member as I want to make this extensible.

View 1 Replies View Related

C++ :: Holding Function In Variable And Changing It Dynamically

Jun 30, 2014

I need a variable that will just hold a function that I can change in the middle of the application, even to different function type with different amount of parameters ... is this even possible? At the moment I have this

struct REPLY {
string *sReply;
function<int()> special = [](){return 0;};
REPLY()

[Code] .....

And then change it back to blank function returning 0 after calling it

(reply.special)();
reply.special = [](){return 0;};

This works fine (there is no reason why it should not, right? Now, if I want to have another function, let's say

void test2(string str) {
MessageBox(NULL, str.c_str(), NULL, NULL);
}

How do I point this one to the variable special, when I want to call it like that (or something similar)

(reply.special)("test string");

is this even possible? if so, how? i tried to create function pointer (didnt compile at all) or use template (neither did this) and how to do this as I discovered functional lib just a while ago.

View 12 Replies View Related

Visual C++ :: CDHtmlDialog - Changing HTML File Dynamically

Apr 9, 2014

I am using CDHtmlDialog in my MFC application to create a UI with HTML, CSS & JavaScript.

In my project there's one dialog created from CDHtmlDialog and a corresponding HTML file for that dialog.

Now during run time i want to change the contents of the HTML file.

Not just the HTML part, i want to change the CSS & JavaScript too.

So basically what am trying to do is, change the entire content of the default HTML file.

Is this possible? If yes, how can i do that?

View 14 Replies View Related

Visual C++ :: MFC Dialog / Changing Images (JPG / PNG) Dynamically In HTML Page?

Sep 6, 2013

I created a MFC dialog using CDHtmlDialog and added a HTML page with many controls and one of them is a IMAGE tag. I got a default image loaded from the hard drive displayed in the HTML page. Up to this part, everything works fine.

Now what i want to do is, dynamically change the image based on the user click on one of the HTML buttons. I don't want this image source to be hard coded in the HTML nor the image source send from the MFC app.

What i want is for the MFC app to send the image data to the HTML in some (binary) format and then the page to display the image.

The possible option i was thinking of was to read the image file which is already in my hard drive as a binary file and send the binary data across to the HTML as a memory buffer, and then use JavaScript to decrypt this binary data and display the image.

Basically what i want is for the HTML page to display a image from the memory. how to do this?

View 5 Replies View Related

C :: Swapping Structures Inside File

Apr 9, 2013

I tried normal swapping method like this (counter is number of structures written in file) :

Code:
fopen("books.txt","r+");
system ("cls");
for(i=1;i<counter-1;i++){
for(j=1+1;j<counter;j++){
fscanf(f," %[^,], %[^,], %[^,],

[Code] ....

But it doesn't do anything.

View 2 Replies View Related

C++ :: Dynamic Structures - Find Average Value Of All Elements In Deque

Dec 17, 2013

I have a question. How to find the average value of all the elements in a deque?

View 2 Replies View Related

Visual C++ :: Access Violation Reading Void Assigned Dynamically Allocated Value Inside Function

Sep 16, 2013

Why the void pointer passed to testb doesn't continue pointing to the allocated integer after the function call returns.

Code:
#include <stdio.h>
#include <iostream>
void* testa() {
return new int(1);

[Code] ....

View 5 Replies View Related

C++ :: Allocating Array Of Pointers To Dynamically Allocated Array?

Jan 18, 2014

I'm trying extremely hard to understand pointers and I have the basic concept down.. I feel as though my knowledge of dynamically allocated pointers and pointers in general is not enough to understand the logic behind what I'm trying to do. The problem is that the donations array must be able to accept any number of donations. I've made it do just that, but there is also an array of pointers which must each point to the same element in the donations array. The program works if I assign int *arrPtr[100] for example, but it does not work if I try to dynamically allocate it to accept the same number of elements for donations entered by the user. Here it's the snippet

#include <iostream>
using namespace std;
//Function Prototypes

[Code]....

View 2 Replies View Related

C++ :: Changing Array Of Characters To A String Array?

Apr 7, 2013

I have an array titled: char TypeOfSong[arraySize] where the array size is 15. I am reading data from a file into this array and the characters can be either 'C', 'D', 'E', or 'R'. Each of these characters stands for a word (sting) and when I output the array, I need the strings to show up, not the characters. I have been reading online and in my book but I can only find information on turning one array with the same characters into a string. How would I go about changing this character array with different characters into a sting?

The characters stand for:

C = Country
D = Dance Party
E = Elevator
R = Rock

View 5 Replies View Related

C++ :: Changing Array Values

Jun 15, 2013

If I have an array of two columns that have the same values and I want to change only the third column how can I go about doing this. The values of the third column will change based on the values in one of the columns which I plug into a math equation. Also how come I can't show a double value in the array?

#include <iostream>
#include <math.h>
#include<iomanip>
#include <vector>
using namespace std;

[code]...

View 7 Replies View Related

C :: In Two Dimensional Array 0,0 Spot Keeps Changing

Jan 12, 2015

I have a 10x10 array, initialized to all zeros. I create 2 random numbers for the purpose of guessing a position in the array.
However, when I print the array, the 0,0 spot keeps shifting to match the 2nd random number generated. Is there something strange about the 0,0 spot?

Here is my code:

Code:
seedrnd();
for (x=0;x<2;x++) {
randArray[x]=rnd(10);
}
for (x=0;x<2;x=x+1)

[Code] .....

The 2nd to last print statement actually prints randColumn. The last print statement correctly prints 0.

View 7 Replies View Related

C :: Changing Order Of Numbers In Array

Dec 10, 2014

I want to write a programm that will reverse the order of the numbers in an array (e.g. as an input 1,2,3.5,4 and as an output i want 4,3.5,2,1) . But i have to problems:

1) I do not know how to properly change the type of a numbers inside an array from int to float or double, changing int to float in front of the a[10], does not change anything instead the code does not want to compile then.

2) I also want to make an array of a number of elements typed by a user with use of a "do" loop and how to put this parameter in the code.

Here is my code:

Code:

// ConsoleApplication3.cpp : Defines the entry point for the console application.//
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[]) {
int a[10], i, n;
int pom;
do {
printf("number of elements in an array a: n = ");

[Code]...

View 5 Replies View Related

C++ :: Macro For Changing Array Size

Nov 22, 2013

I'm trying building a new macro for change the array size:

#define redim(varname,x) ((sizeof(varname)*) realloc (varname, x * sizeof(varname)));
int b;
redim(b,3);

error message:
"error: expected primary-expression before ')' token"

what isn't right with these macro?

View 10 Replies View Related

C++ :: Dynamically Expanding Array

May 28, 2013

Consider the following:

Code:
int *p;
p = new int[5];
for(int i=0;i<5;i++)
*(p+i)=i;

Now suppose we want to add a 6th element (without using vector)

One way is to copy it across to a larger array:

Code:
int *p;
p = new int[5];
for(int i=0;i<5;i++)
*(p+i)=i;

// realloc
int* temp = new int[6];
std::copy(p, p + 5, temp);
delete [] p;
p = temp;

This looks like a very expensive operation and im looking for other ways.

Three questions regarding the above: Not using vector, is this the best way to do this?What about using realloc? How would I use realloc in this situation?Any other ways apart from realloc or vector?

View 1 Replies View Related

C++ :: Dynamically Realloc 2D Array

Dec 18, 2014

I would like to realloc a 2D array. I have a counter, itime, it increases each step. Each step, I would like to reallocate my array, keeping the old values, and add new values to the array. When itime=1, I use only malloc, because it is allocated for the first time. When itime increases (e.q. itime=2), realloc comes into process. In the realloc process the GUI crashes.

int itime;
char ** solpointer;
itime = 1;
do {
if( itime == 1 ) {
solpointer = (char**)malloc(sizeof(char*) * itime);
solpointer[itime-1] = (char*)malloc(sizeof(char) * 32);

[code]....

View 3 Replies View Related

C/C++ :: How To Dynamically Expand Array

Sep 8, 2014

I am working on expanding an array and my approach was to do this by copying the array into a bigger array. For this problem I cannot use vectors so what I did was the following:

int *a;
a = new int[5];
for(int i=0;i<5;i++)
*(a+i)=i;
// reallocating array
int* temp = new int[6];
std::copy(a, a + 5, temp);
delete [] a;
a = temp;

Is this approach correct, also how could I implement this on a program to expand an array to double its size or could I not use this to expand an array to double its size?

View 2 Replies View Related

C :: Array Containing Pointers To Structures?

Aug 9, 2013

How do I store pointers to a struct in an array ? I am using sprintf to concatenate some values together and then output it to an array in its 1st argument. A portion of my code is shown below.

Code:

int count = 0;
struct addx {
int a;

[Code].....

View 1 Replies View Related

C :: Storing Array Of Structures

May 4, 2013

So i have a program with the structure

Code:

char record[20];
typedef struct{
int id;
char title[20];
char subject[20];
char faculty [20];
int level;
char fname[25];
}report;
int recno,i;
report list[100];

I need to store the hundred records into a file. What are the functions and elements i should use/introduce.

View 2 Replies View Related

C/C++ :: Initializing Array Of Structures

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

C++ :: Dynamically Allocating Multidimensional Array?

Nov 24, 2013

Working on this one from the Jumping into c++ book. The book asks that I create a multidimensional array at run time based on user input and fill it with a multiplication table

My code compiles fine but throws an uninitiated error for p when I try and run it.

Code:
void multiDimentionalMultiplication(int x, int y, int z){
int ***p;
**p = new int[x];
std::cout << "Allocating array.

[code]....

View 8 Replies View Related

C++ :: Size Of Dynamically Created Array

Dec 2, 2013

I have declared an array like:

/***********Creating an m*p array**********************/
B = new int *[m];

for(row=0;row<m;++row)
B[row] = new int[p];

How to find the number of elements in it?

The statement

cout << "number of elements in array B equals " << sizeof(B) << endl;

returns 4 each time the program runs

View 3 Replies View Related







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