pointers

sending a struct to a function, previously defined with a pointer

Edit: Forget it. it was another part of the code (actually the problem was a secondary element. another pointer but not allocated with malloc, just declared, so i think the memory was allocated in another place). the example now can compile. thanks guys. im sorry for my typos but english isnt my native language(isnt a good escuse but i...

Need to convert char* (pointer) to wchar_t* (pointer)

I am doing some serial port communcation to a computer controlled pump and the createfile function I used to communicate requires the com port name to be parsed as a wchar_t pointer. I am also using QT to create a form and aquire the com port name as a QString. This QString is converted to a char array and pointed to as follows: c...

C++ Returning multidimension array from function

How do I return a multidimensional array hidden in a private field? class Myclass { private: int myarray[5][5]; public: int **get_array(); }; ........ int **get_array() { return grid; } cannot convert 'int ()[5][5]' to 'int*' in return test.cpp /Polky/src line 73 C/C++ Problem ...

Pointer to c++ string

Hi, in the following code, I am using a pointer to a c++ string in the change() function. Is there anyway to use the string class' operators when working with a pointer to a string? For example, at() works for the [] operator, but is there any way to use the [] operator? #include <string> #include <iostream> using namespace std; void...

Simple c++ pointer casting

Can someone explain this to me: char* a; unsigned char* b; b = a; // error: invalid conversion from ‘char*’ to ‘unsigned char*’ b = static_cast<unsigned char*>(a); // error: invalid static_cast from type ‘char*’ to type ‘unsigned char*’ b = static_cast<unsigned char*>(static_cast<void*>(a)); // everything is fine What makes the dif...

Size of a struct with two void pointers is 4?

I don't understand why struct e{ void * a; void * b[]; } has sizeof(e) == 4 while struct f{ void * a; void * b; } has sizeof(f) == 8. ...

How to add a pointer to a 3-D plot in MATLAB?

I want to plot a "Pointer" in a 3-D plot. I want this "pointer" to point at a certain spot on a sphere that I have graphed. This pointer does not have to have an arrowhead but would be nice if it did. Is the only way to plot a line with a jpg at the end? Not too sure... Thanks for any help! ME ...

templated function pointer

I have an approach to call delayed function for class: //in MyClass declaration: typedef void (MyClass::*IntFunc) (int value); void DelayedFunction (IntFunc func, int value, float time); class TFunctorInt { public: TFunctorInt (MyClass* o, IntFunc f, int v) : obj (o), func (f), value (v) {} virtual void operator()(); protected: ...

Pointers to tables in SQLite

Say I have a table of apples (apple_id). And for each apple I have a history of its weight over time. How to structure it so that every time an apple is added, an associated table is created with its weight history? Having only one table of weight history for all apples (apple_id,age,weight) seems like a performance drain when looki...

can anyone work out why my app is crashing when i move the slider

When i move the slider it crashes the app. i know it is something to do with the argument i am passing to maxProcess method. it works fine if i take this out. but i need it to update the newEvent objects instance variable. Any ideas. This is what i have been told in another forum but i don;t know how to do this "this code declares a new...

Null Pointer Exception

Hello All, I have been using a driver to test one of my data structures(Binary Search Tree) and i have come across this issue. -It happens when i insert more than 2 objects into the bst -What I am trying to do: I am inserting 4 objects into the tree, then i am deleting 2 objects, and then printing out my find method so that it displays w...

pointer to a char pointer and arrya of char pointers

is there any difference between an array of char pointers and a pointer to a char pointer? ...

Weird problem using UINib / pointer going AWOL

I have something weird going on with using UINib, although I suspect the real problem may be buried elsewhere. My app is using a tableview, the content for the cells has been prepared in Interface Builder due to their complexity. For new cells (as opposed to reused ones), the contents of the nib are instantiated using the UINib Class. B...

Why does this program give segmentation fault?

Hi, It's a beginners question: Why is this breaking/giving an error? #include <stdio.h> #include <stdlib.h> #include <string.h> char *strtrim_right(char *p) { char *end; int len; len = strlen( p); while (*p && len) { end = p + len-1; if(isalpha(*end)) *end =0; else break; } return(p);...

Double array through pointers in C

I want to scan a 2D array with the help of pointers and have written this code, could you tell me why the compiler gives errors? #include<stdio.h> #include<stdlib.h> int main(void) { int i,j,n,a,b; int (*(*p)[])[]; printf("\n\tEnter the size of the matrix in the form aXb\t\n"); scanf("%dX%d",&a,&b); p=(int (*(*p)[b])...

Why does self.navigationController become nil?

I have this code: ViewController2 *childView = [[ViewController2 alloc] initWithNibName:@"ViewController2" bundle:nil]; [self.navigationController pushViewController:childView animated:YES]; I the first line, self.navigationController has a value. On the second line, its value becomes 0. Why is that? ...

2D array through pointers.

I want to scan a 2D array with the help of pointers and have written this code, could you tell me why the compiler gives errors? I know how to use double pointers to do the same, i was experimenting with this one. #include<stdio.h> #include<stdlib.h> int main(void) { int i,j,n,a,b; int (*(*p)[])[]; printf("\n\tEnter the size...

Pointers and cstring beginner troubles

I have a problem with the function replace. What I want to accomplish is to replace some special characters, but I haven't written the code yet. So in the replace function we can at this moment just say that the function should print line for line the way I have tried to write. Can someone please correct this function? I can’t really get...

C Programming - Malloc Structs and undefined arrays

I am writing a program in C and I am trying to create these structs. I have three of them: the first consisting of 2 ints and 2 chars, the second consisting of an int and an undefined array of pointers to the first one, and a third which contains 4 longs and 2 ints along with an undefined array of pointers to the second. I am having ...

C++ overloading typecast operator for pointers

I have a conversion like this: Class1 *p1; Class2 *p2 = new Class2(); p1 = (Class1 *) p2; Can I override the typecast operator above to return a custom Class1 object pointer? If yes how? EDIT: My exact problem is that I have code like this: if (*$1 == ArrayType(AnyType())) { $$ = ((ArrayType *) $1)->getElementsType(); } Operat...