pointers

Correct syntax for C pointer datatypes

I vaguely recall seeing this before in an answer to another question, but searching has failed to yield the answer. I can't recall what is the proper way to declare variables that are pointers. Is it: Type* instance; Or: Type *instance; Although I know both will compile in most cases, I believe there are some examples where it is ...

How to replace strings in C, just using stdio.h??? Help, please!!!

i need to create a small program: user enter 1st string ex: I'm a beautiful girl then he needs to replace for example 'beautiful' to 'clever' can use just stdio.h and pointers as well help me, pls!!! ...

How to replace strings in C, just using stdio.h???

It's a part of my final project; I don't understand C well. I have just this, and I don't know anything more. Please don't delete my question. I was looking for the answer a long time. I guess I'm not the only student with this problem. And why is there no option to send a private message or see a user's e-mail? wow, guys...actually i ...

Another C++ learning moment: returning strings from functions

I've got some basic questions about C++. Consider the following code in which I attempt to return a string. const std::string& NumberHolder::getValueString() { char valueCharArray[100]; sprintf_s(valueCharArray,"%f",_value); std::string valueString(valueCharArray); return valueString; } I'm attempting to return a stri...

How do I create a custom mouse pointer for a website?

Hi there, I have seen some websites with a custom mouse pointers rather than the normal "operating system" cursors. I know this is very easily done in flash and such; but I am not talking about those websites. Is it really difficult to make a custom mouse pointer for a normal webpage? I cant remember the good websites, but there is one...

User defined array sizes in C

I'm reading through "Illustrated C" and the first exercise question asks: Program MATMUL multiplies matrices of fixed size. Make the program deal with any specified sizes. So below is the code that I have come up with thus far. However I read that all attributes need to be declared before the main function. So how do I get custom s...

push_back of unique_ptr

What's wrong here? #include <memory> #include <vector> int main() { std::vector<std::unique_ptr<int>> vec; int x(1); std::unique_ptr<int> ptr2x(&x); vec.push_back(ptr2x); //This tiny command has a vicious error. return 0; } The error: $ g++ -std=gnu++0x main.cpp In file included from c:\mingw\bin\../lib/gcc/min...

Copying data into a reference in java (lack of pointer problem)

So I have an ArrayList in java. And what I'm doing is creating a new list with updated values. But I want to put those new values into the original ArrayList. This is important because I'm passing the original arraylist reference to an object that I no longer have access to, but I need to keep its contents up to date. Is there any way to...

Executing member function of class through pointer to abstract parent of said class.

I have created an abstract base class Animal which has public virtual abstract method makeSound(). I created a subclass Cow which implements Animal.makeSound() as you would expect (you know... "moo"). And I have a Farm class which holds a private member variable std::vector<Animal*> animals. In one of the Farm methods I iterate over a...

What is the simplest way to "cast" a member function pointer to a function pointer in C++?

I want to provide a member function for the "comp" parameter of an STL algorithm like lower_bound( ..., Compare comp ). The comp() function accesses a non-static member field so it must itself be a non-static member but the type of a non-static member function pointer is different from that of an ordinary function pointer. What is the ...

Pointers to elements of std::vector and std::list

Hi, I'm having a std::vector with elements of some class ClassA. Additionally I want to create an index using a std::map<key,ClassA*> which maps some key value to pointers to elements contained in the vector. Is there any guarantee that these pointers remain valid (and point to the same object) when elements are added at the end of the...

Pointers in structs passed to CUDA

Hi folks, I've been messing around with this for a while now, but can't seem to get it right. I'm trying to copy objects that contain arrays into CUDA device memory (and back again, but I'll cross that bridge when I come to it): struct MyData { float *data; int dataLen; } void copyToGPU() { // Create dummy objects to copy int ...

In C++, any general guidelines for handling memory allocation/deletion?

Probably all that I'm asking for is a link to a website that I have yet to find. But coming from a Java background, what are the general guidelines for handling memory allocation and deletion in C++? I feel like I may be adding all sorts of memory leaks to my application. I realize that there are several variants of smart pointers, an...

Does myVector.erase(myObject) call delete on myObject?

Similar to this question but with objects instead of pointers. If I have the following code Foo f; vector<Foo> vect; vect.push_back(f); vect.erase(vect.begin()); Where does my object go? Is delete called on it? What if someone else holds a pointer to it? Is this a memory leak? ...

Basic C pointer question

Hi all, It has been a while since I last programmed C, seems I have forgotten everything in the meantime... I have a very simple pointer question. Assuming that I have a function that computes a sum through loop iteration. Not only should this function return the loop counter but also the sum it computed. Since I can just return one val...

C++ to C# conversion of SendMessage using COPYDATASTRUCT

I'm converting a C++ application into C# which has generally been fairly straight forward, but now I'm dealing with pointers and running into problems. This is the original C++ code ShockVideoInfo* pVideoInfo = new ShockVideoInfo; COPYDATASTRUCT cd; cd.dwData = bSelf ? SHOCK_REQUEST_SELFVIEW_WINDOW : SHOCK_REQUEST_MAINVIEW_WIND...

Passing a pointer to an object onto a child application.

So basically, I have two applications. Application 1 launches Application 2 but it remains in memory. When Application 2 is started it needs to be given a pointer to a CALayer object which is stored in the first application. The object represented by the pointer needs to be accessible by both applications. I am using Objective-C. I wou...

Substracting pointers: Where does this missing level of indirection come from?

Hi everybody, I'm having trouble understanding the behavior of the MS VC compiler on this one. This line compiles fine, but the result I get is not what I'd expect at all: this->Test((char *)&CS2 - (char *)&CS1 == sizeof(void *)); The CS1 and CS2 arguments are declared as follows: myFunction(tCS1* CS1, tCS2* CS2) {... tCS1 and tCS2...

volatile variables as argument to function

Having this code: typedef volatile int COUNT; COUNT functionOne( COUNT *number ); int functionTwo( int *number ); I can't get rid of some warnings.. I get this warning 1 at functionOne prototype [Warning] type qualifiers ignored on function return type and I get this warning 2, wherever I call functionTwo with a COU...

Can a pointer (address) ever be negative?

I have a function that I would like to be able to return special values for failure and uninitialized (it returns a pointer on success). Currently it returns NULL for failure, and -1 for uninitialized, and this seems to work...but I could be cheating the system. iirc, addresses are always positive, are they not? (although since the comp...