I was working on my advanced calculus homework today and we're doing some iteration methods along the lines of newton's method to find solutions to things like x^2=2. It got me thinking that I could write a function that would take two function pointers, one to the function itself and one to the derivative and automate the process. This ...
Hi I'm working with C and I have a question about assigning pointers.
struct foo
{
int _bar;
char * _car[SOME_NUMBER]; // this is meant to be an array of char * so that it can hold pointers to names of cars
}
int foofunc (void * arg)
{
int bar;
char * car[SOME_NUMBER];
struct foo * thing = (struct foo *) arg;
bar =...
Declare:
LPWSTR** lines= new LPWSTR*[totalLines];
then i set using:
lines[totalLines]=&totalText;
SetWindowText(totalChat,(LPWSTR)lines[totalLines]);
totalLines++;
Now I know totalText is right, cause if i SetWindowText using totalText it works fine. I need the text in totalLines too.
I'm also doing:
//accolating more memory.
...
Here is two variants. First:
int n = 42;
int* some_function(int* input)
{
int* result = new int[n];
// some code
return result;
}
int main()
{
int* input = new int[n];
int* output = some_function(input);
delete[] input;
delete[] output;
return 0;
}
Here the function returns the memory, allocated insi...
Please take a look at this example:
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class mySubContainer
{
public:
string val;
};
class myMainContainer
{
public:
mySubContainer sub;
};
void doSomethingWith( myMainContainer &container )
{
container.sub.val = "I was modified";
}
int main( )
{
...
Hello,
In my app, i've created the TList type list where i store the pointers to 1 string and 2 float(real) values for every 3 items.
aList.Add(@sName); //string
aList.Add(@x1); //float
aList.Add(@x2); //float
Then, i want to get the values out from the list, but i could only do that for string
sStr := string(lList.items[i]);
But ...
In C, I have declared a memory area like this:
int cells = 512;
int* memory = (int*) malloc ((sizeof (int)) * cells);
And I place myself more or less in the middle
int* current_cell = memory + ((cells / 2) * sizeof (int));
My question is, while I increment *current_cell, how do I know if I reached the end of the allocated memory ar...
Hi All,
I am reading the contents of the file using fread into an char array. But I am not sure why it is not getting printed in the output. Here is the code:
void getInfo(FILE* inputFile)
{
char chunk[4];
int liIndex;
for (liIndex = 0 ; liIndex < 4 ; liIndex++)
{
fread(chunk, sizeof(char), 4, inputFile);
}
prin...
According to the responses in "Why subtract null pointer in offsetof()?" (and my reading of K&R), the C standard doesn't require that (size_t)((char *)0) == 0. Still, I've never seen a situation where casting a null pointer to an integer type evaluates to anything else.
If there is a compiler or scenario where (size_t)((char *)0) != 0, ...
I have a structure:
struct mystruct
{
int* pointer;
};
structure mystruct* struct_inst;
Now I want to change the value pointed to by struct_inst->pointer. How can I do that?
EDIT
I didn't write it, but pointer already points to an area of memory allocated with malloc.
...
Hello, I try to call a function which passed as function pointer with no argument, but I can't make it work.
void *disconnectFunc;
void D::setDisconnectFunc(void (*func)){
disconnectFunc = func;
}
void D::disconnected(){
*disconnectFunc;
connected = false;
}
...
Hi,can anybody tell me,the meaning of wild pointer in C, how it obtain and is this available in C++ ?
...
Hi,
I am trying to do the following:
in main.cpp:
// Create an array of pointers to Block objects
Block *blk[64];
for (i=0; i<8; i++) {
for (j=0; j<8; j++) {
int x_low = i*80;
int y_low = j*45;
blk[j*8+i] = new Block(30, x_low+40.0f, y_low+7.5f, &b);
}
}
And then I am trying to pass it to the graphics object I have cr...
Hi all, I want to ask about pointer in C++
I have some simple code:
int add(int a, int b){
return a+b;
}
int runner(int x,int y, int (*functocall)(int, int)){
return (*functocall)(x,y);
}
now, suppose I call those functions using this way :
cout<<runner(2,5,&add);
or maybe
cout<<runner(2,5,add);
is there any difference? beca...
C really isn't my strong point and after reading 3 chapters of a book on the subject and spending ages trying to get stuff working it just doesn't:
#include <stdio.h>
char *a,*b;
int main( )
{
char input[10];
fgets(input,sizeof input, stdin);
a = input;
fgets(input,sizeof input, stdin);
b = input;
printf("%...
How would I go about writing my own stream manipulator class?
Basically what I'm trying to wrap my head around is storing the reference to the underlying stream in the writer. For example, when writing to a memory stream using a StreamWriter, when a Write() is made, the underlying memory stream is written to.
Can I store the referenc...
Hi,
I can't understand this result...
The code:
void foo(void * key, size_t key_sz) {
HashItem *item = malloc(sizeof(HashItem));
printf("[%d]\n", (int)key);
...
item->key = malloc(key_sz);
memcpy(item->key, key, key_sz);
}
void bar(int num) {
foo(&num, sizeof(int));
}
And I do this call: bar(900011009);
...
Hi everybody, I'm having the above error request member rv in something not a structure of union. I've googled it and several answers told me it's when working with a pointer but tries to access it as a struct, where I should be using -> instead of .
int foo(void * arg, struct message * msg)
{
struct fd_info * info = (struct som...
Hi,
Check the below code
int add(int a, int b)
{
return a + b;
}
void functionptrdemo()
{
typedef int *(funcPtr) (int,int);
funcPtr ptr;
ptr = add; //IS THIS CORRECT?
int p = (*ptr)(2,3);
cout<<"Addition value is "<<p<<endl;
}
In the place where I try to assign a function to function ptr with same function si...
Hi,
I have trouble seing the utility of the function pointers. I guess it may be useful in some cases (they exist, after all), but I can't think of a case where it's better or unavoidable to use a function pointer.
Could you give some example of good use of function pointers (in C or C++)?
Many thanks :)
...