C++ :: Accessing Inside Structure Via Struct Pointer To Struct Pointer
Jun 5, 2012
"
#include <stdio.h>
struct datastructure {
char character;
};
void function(struct datastructure** ptr);
[Code] ....
These codes give these errors:
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
These errors are related to
"
*ptr->character='a';
printf("Ptr: %c",*ptr->character);
"
I want to access "character" data inside the structure "trial" by a pointer to pointer "ptr" inside function "function",but I couldn't find a way to do this.
View 3 Replies
ADVERTISEMENT
Mar 19, 2014
i had a structure as follows:
struct a{
int x;
struct b{
int y;
b *next;
}b;
};
when i try to access as follows:
struct a *a;
a->b=a->b->next;
i got the following error: base operand of ‘->’ has non-pointer type
View 1 Replies
View Related
Aug 25, 2014
I want to have a function pointer inside a typedef struct but I get a segmentation fault when I run my code. Here's my code:
#include <stdio.h>
typedef struct Foo {
void (*bar)(int);
} Foo;
void func(int x) {
printf("display: %d
[Code] ....
View 2 Replies
View Related
Mar 12, 2014
This is with Linux gcc
Code:
typedef struct _a
{
int id;
} a;
typedef struct _b
{
a my_a;
my_a.id = 1; // error: expected specifier-qualifier-list before "my_a"
} b;
I get error: expected specifier-qualifier-list before "my_a"
I must set the id for the kind of struct created inside the struct def because main() will be casting based on this id. Thats how I will know which structure b contains by it's id, there could be hundards of different structs with different values I will cast to the correct one and know it's members by it's id. How do I ?
View 10 Replies
View Related
Mar 14, 2013
I'm trying to call a function via a function pointer, and this function pointer is inside a structure. The structure is being referenced via a structure pointer.
Code:
position = hash->(*funcHash)(idNmbr);
The function will return an int, which is what position is a type of. When I compile this code,
I get the error: error: expected identifier before ( token.
Is my syntax wrong? I'm not sure what would be throwing this error.
View 3 Replies
View Related
Mar 6, 2015
how can I call and print the Pointer:
ptr->address
Code: #include<stdio.h>
struct account {
int address;
int value;
[code]....
View 5 Replies
View Related
Mar 9, 2015
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main() {
struct stock{
char symbol[5];
int quantity;
float price;
[Code] ....
- In the final output
Value
%.2f
- How is the final pointer reference at line33 leading to the output %.2f ? (i do understand that the %% is used to display a %] ....
View 1 Replies
View Related
Jan 14, 2015
I am currently trying to printf several values of a struct pointer but with little success.
#include"Header.h"
/*
In header:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
struct FileStruct {
char FileQuestion[64];
[Code] ....
As you can see I am trying to re-crate the output from the first loop in my second loop, however it is with little success. The second loop's first run re-crates the last output of the first loop and if I use FileStructPointer++ or -- the output goes broke.
See attached for how it looks in the console window.
Attached image(s)
View 3 Replies
View Related
Nov 23, 2013
This is a c++ Code. I want to read a address to a pointer. When I try to do so it generates an error. I did is >> obj1[0].contentAdress; in main.
struct node3{
node3(){
nextContent = NULL;
for (int i = 0; i<1020; i++)
content[i] = '';
[code]...
no operator found which takes a right-hand operand of type 'node3 *' (or there is no acceptable conversion)
View 12 Replies
View Related
Nov 28, 2014
I am trying to store data in a struct to be able to read it latter . have problems initializing this.
struct FoodAndDrink {
struct Food {
char* CannedGoods[2] = {
"Canned Spaghetti",
"Canned Tuna",
[code] .....
View 7 Replies
View Related
Mar 17, 2013
i need to return a struct pointer dynamically allocated inside a function call void function() which is done using 'out parameters' in following code
struct my_struct {
int x;
} void my_function( my_struct** result ) {
my_struct* x = new my_struct{ 10 };
//...
*result = x;
}
Now i have a doubt, so if i want to print the return value from struct pointer, should i need to print it in the void function() or in the caller the function...
View 3 Replies
View Related
Mar 24, 2013
I have a queue of structs. I would like to access one of the two pieces of data at the front of the queue that each struct maintains.
Here is some of my code:
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <queue>
using namespace std;
[Code] ....
What I am asking is how do I get the priority of the struct item at the front (lane1.front()), in this case?
View 8 Replies
View Related
Mar 18, 2014
The program I'm working on is a very basic relational database. I've isolated my problem for simplicity. I get a segfault right here when I try to access db->relationCount. I tried printing db->relationCount from within loadDB and that worked,
[code]
loadDB(db, configFile);
printf("%d",db->relationCount);
fflush(stdout);
View 5 Replies
View Related
Dec 9, 2014
I've been working for some number of days on this code to take information about movies from both a file and the user, store the infos in an array of structs, and at the end, write all the info out to a file. I'm having some problems with an error message reading:
"prog.c:102:11: error: subscripted value is neither array nor pointer nor vector"
this error occurs in many lines (which I will label specifically below -- they are everywhere where I am trying to access/modify an individual element of a struct element of the array).
A few examples of where I am having the problems are lines:
39, 52-55, 70, 72, and 86 (and more of the same exact variety).
I am obviously rather systematically doing something wrong, but I am quite certain all of these are the exact same mistakes.
I pull up also 2 or 3 other errors, but I don't think they are related and should be able to fix them quickly once I work out this conundrum.
#include <string.h>
#include<stdlib.h>
#include <stdio.h>
int moviecount =0;
typedef struct{
int year;
[Code] .....
View 5 Replies
View Related
Mar 26, 2013
I've been reading the tutorials on Friendship and Inheritance [URL] ..... but I still don't understand why I can't access members of the same struct type.
bool wordBeginsAt (int pos) {
if (pos == 0)
return true;
///use the 'message' string
Message go;
return isAlphanumeric(go.messageText[pos]) && (!isAlphanumeric(go.messageText[pos-1]));
}
The code above is located in a source file, where the function isAlphanumeric passes a char value, and Message is the struct containing the string I want to access. Below is the declaration of the struct and string located in the corresponding header file.
struct Message{
.
.
.
private:
std::string messageText;
};
My frustration comes when I try to call and assign messageText like the tutorial does to its private members, but I keep getting an error saying I can't access the string because it is a private member. Is there a way to access the string without having to pass it through the function wordBeginsAt?
View 6 Replies
View Related
Apr 30, 2013
I have a vector (structures) in a struct (instances). I make a declaration of this struct called instance. The vector is a 3-layer vector of pointers, like so:
vector < vector < vector<scene::IAnimatedMeshSceneNode*> > > structures; (The type is from Irrlicht 3D). I have 3 nested "for" loops which looks similar to the following:
for (int a = 0; a < instance.structures.size(); a++) { /*note:vector size previously set*/
for (int b = 0; b < instance.structures[a].size(); b++){
for (int c = 0; c < instance.structures[a][b].size(); c++) {
if (1) { //checking value of variable not included in snippet
(instance.structures)[a][b][c] = smgr->addAnimatedMeshSceneNode(fl);
(instance.structures)[a][b][c]->setPosition(renderPos);
}
}
}
}
The problem is in these two lines, I think:
(instance.structures)[a][b][c] = smgr->addAnimatedMeshSceneNode(fl);
(instance.structures)[a][b][c]->setPosition(renderPos);
These are currently referencing the pointers, it seems. The program compiles but crashes at this point. I need them to reference the values of the pointers. Problem is, I don't know where to put the dereference operator (*). Where should it go?
View 4 Replies
View Related
Apr 5, 2013
I currently have a file which allows inputs to record different transistor types. I then have the task of accessing this structure, find a certain manufacturer ID, and print the information about this particular transistor.
My problem is accessing the array to search through.
Here is my code:
Code:
#include "stdio.h"
const int IDLEN=30; //All constant values defined
const int POLARITYLEN=3;
const int MAXSTOCKITEMS=10;
//First structure defined
struct TransistorRec {
[Code]......
The errors I am currently getting are on line 54 'expected primary-expression before "struct"' and on line 60 ' 'maunfacturersID' undeclared'
View 11 Replies
View Related
Feb 29, 2012
I'm currently working on the ioquake3 engine . The ioquake3 engine is separated into 2 different main threads at runtime: the gamecode and the engine. Both are communicating but not all information and my problem resides here.
In the gamecode, there's a struct called gentity_t which contains a lot of fields:
Code:
typedef struct gentity_s gentity_t;
struct gentity_s {
entityState_ts;// communicated by server to clients
entityShared_tr;// shared by both the server system and game
// DO NOT MODIFY ANYTHING ABOVE THIS, THE SERVER
// EXPECTS THE FIELDS IN THAT ORDER!
//================================
struct gclient_s*client;// NULL if not a client
[Code] ....
This whole entity is passed to the engine at runtime, but only the first two fields are declared for the engine:
Code:
// the server looks at a sharedEntity, which is the start of the game's gentity_t structure
typedef struct {
entityState_ts;// communicated by server to clients
entityShared_tr;// shared by both the server system and game
} sharedEntity_t;
My problem is that I need to access the health field of gentity_t from the engine. Technically, this is possible, but the health field is not declared in sharedEntity (which is the same memory address than gentity_t in the gamecode), so this is not straightforward.
I am looking for an elegant way to do this, and my constraint is that I must not edit the gamecode, only the engine.
The solutions I've thought:
- Just copy the whole gentity_t fields into sharedEntity_t. This would work I think but would be redundant, and I would like to avoid copying this huge set of fields.
- Include the two headers files declaring the gentity_t and sharedEntity_t structs, and create a Getter and a Setter functions that would cast a gentity_t over a sharedEntity_t and return/set a field. The problem is that I can't simply include them because they are both including some common headers files and this produce a recursive include error (and I can't modify the files to add a check, these are normally in the gamecode).
- Directly access the health field using a clever memory pointer, but I don't even know if that's possible given the huge number of fields prior health with many different types?
View 2 Replies
View Related
Jun 23, 2013
while writing code i got a question. For example i created a class named as unit.
Think a simple game, and the unit class will belong the units.İf i give the preferences as private one by one, it will be irregular. For a detailed game; height, weight, race, hair preferences, eyes... Strength, dexterity, charisma, intelligence, wisdom, constution... experience, damage, armor...
and should i use struct to group them? And how to can i use struct at the inside of class as private?
View 2 Replies
View Related
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
Jul 22, 2013
Can typedef and struct be put inside a class like below?
Code:
class classA {
private:
typedef void(classA::*aFnPtr_t) (); //pointer-to-member function
struct strctA {
int a;
int b[100];
};
typedef struct strctA strctA_t;
typedef void (classA::*bFnPtr_t)(strctA_t*); //pointer-to-member function
...
}
View 8 Replies
View Related
Jan 4, 2014
I am parsing a binary data file by casting a buffer to a struct. It seems to work really well apart from this one double which is always being accessed two bytes off, despite being in the correct place.
Code:
typedef struct InvoiceRow {
uint INVOICE_NUMBER;
...
double GROSS;
...
char VAT_NUMBER[31];
} InvoiceRow;
If I attempt to print GROSS using printf("%f", row->GROSS) I get 0.0000. However, if I change the type of GROSS to char[8] and then use the following code, I am presented with the correct number...
Code:
typedef struct example {
double d;
}
example;
example *blah = (example*)row->GROSS;
printf("%f", blah->d);
View 7 Replies
View Related
Apr 24, 2013
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct info info;
[Code] ....
View 2 Replies
View Related
Jun 20, 2013
I have the code bellow, and i print the data but cannot assign it to global variable.
struct frequency_data {
char frequency[10];
int32 frequenca_mesatare;
int16 PWM_F;
int32 PR2;
[Code] ....
View 5 Replies
View Related
Sep 14, 2014
#include <stdio.h>
#define MAX_USERS 20
struct {
char ID[10];
char Name[40];
int Pos;
[Code] .....
I was attempting something weired with address to move data around when I discovered that the size of the array is not what I expected. I am passing this structure as &Users to a function that declares it as a void *, then I can deal with chunks of data (memmove) and not have to worry about index or things like that. However...sizeof is returning something I do not understand.
View 9 Replies
View Related
Apr 16, 2013
I am trying to create a class type structure using struct instead of classes.
Code:
#include <iostream>
#include <stdlib.h>
using namespace std;
struct myclass {
int * array;
int nelements;
[Code] ....
Guess what I am asking is using the pointer in the first code section better or is there another way'. I don't know about making the second code work.
View 3 Replies
View Related