i.e. -
int function(char* txt)
{
sprintf(txt, "select * from %s;", table);
//How do I set last char in buffer to NULL here?
}
so if the text in table some how was 500 chars long and txt in the main was only defined as 100....
thanks.
...
Having some maps defined as:
var valueToSomeType = map[uint8]someType{...}
var nameToSomeType = map[string]someType{...}
I would want a variable that points to the address of the maps (to don't copy all variable). I tried it using:
valueTo := &valueToSomeType
nameTo := &nameToSomeType
but at using valueTo[number], it shows
internal...
Cosider the following code:
class Foo
{
Monster* monsters[6];
Foo()
{
for (int i = 0; i < 6; i++)
{
monsters[i] = new Monster();
}
}
virtual ~Foo();
}
What is the correct destructor?
this:
Foo::~Foo()
{
delete [] monsters;
}
or this:
Foo::~Foo()
{
for (int i = 0; i...
I think I understand references and pointers pretty well. Here is what I (think I) know:
int i = 5; //i is a primitive type, the value is 5, i do not know the address.
int *ptr; //a pointer to an int. i have no way if knowing the value yet.
ptr = &i; //now i have an address for the value of i (called ptr)
*ptr = 10; //Go to the value...
Language : C++
Platform : Windows Server 2003
I have an exe calling a DLL.
EDIT :
(exe is not doing anything, it calls few global function which does everything related to DLL within DLL. It does not explicitly new any of DLL classes)
I allocate (new) the memory for class A within the DLL, it returns me a non-local heap pointer.
I...
I have three classes:
class Rtss_Generator {
int mv_transfersize;
}
class Rtss_GenSine : Rtss_Generator
class Rtss_GenSineRpm : Rtss_GenSine
Rtss_GenSine creates a thread in his constructer, it is started immediatly and the threadfunction is off-course declared static, waiting for an event to start calculating.
the problem: all t...
I'm wondering if anyone can explain the following to me: If I write
int i = 0;
float* pf = i;
I get a compile error (gcc 4.2.1):
error: invalid conversion from ‘int’ to ‘float*’
Makes sense - they are obviously two completely different types. But if instead I write
const int i = 0;
float* pf = i;
It compiles without error. Wh...
Dear all,
I'm a beginner programmer in C++.
Recently, I'm working on image processing thing using C++.
but I have some problem that I want to ask. Suppose I have some code as follow:
for (int i=0;i<100000;i++)
{
int * a = new int[10000];
//do something
delete [] a;
}
When I executed that code, I receive runtime error, Heap Err...
What is purpose of this keyword. Doesn't the methods in a class have access to other peer members in the same class ? What is the need to call a this to call peer methods inside a class?
...
I have the following code
#include <iostream>
#include <vector>
class Entity {
public:
virtual void func() = 0;
};
class Monster : public Entity {
public:
void func();
};
void Monster::func() {
std::cout << "I AM A MONSTER" << std::endl;
}
class Buddha : public Entity {
public:
void func();
};
void Buddha::func() {
std...
Given the following x86 assembly instructions:
mov esi, offset off_A
cmp esi, offset off_B
how would I get the offsets (the second operand) at runtime ? This is the scenario: A program (injected into the process at runtime) replaces the offsets with a few of its own, resulting in:
mov esi, offset off_X
cmp esi, offset...
I would like to write an address in a text file, which can be read by fscanf and dereferenced by C after reading the pointer. How do I write the address in the file?
edit:
i don't mean to be rude, but i know that this is exactly what i need, so if anyone can please just list the answer, and not ethical reasons for why i shouldn't be doi...
Following an hot comment thread in another question, I came to debate of what is and what is not defined in C99 standard about C arrays.
Basically when I define a 2D array like int a[5][5], does the standard C99 garantee or not that it will be a contiguous block of ints, can I cast it to (int *)a and be sure I will have a valid 1D array...
The question at
http://stackoverflow.com/questions/1145722/simulating-pointers-in-python
asking how to simulate pointers in Python had a nice suggestion in the solutions, namely to do
class ref:
def __init__(self, obj): self.obj = obj
def get(self): return self.obj
def set(self, obj): self.obj = obj
which can then be use...
I have a fairly good understanding of the dereferencing operator, the address of operator, and pointers in general.
I however get confused when I see stuff such as this:
int* returnA() {
int *j = &a;
return j;
}
int* returnB() {
return &b;
}
int& returnC() {
return c;
}
int& returnC2() {
int *d = &c;
return *...
I need help with malloc() inside another function.
I'm passing a pointer and size to the function from my main() and I would like to allocate memory for that pointer dynamically using malloc() from inside that called function, but what I see is that.... the memory, which is getting allocated, is for the pointer declared within my called...
I'm trying to create a structure array which links input strings to classes as follows:
struct {string command; CommandPath cPath;} cPathLookup[] = {
{"set an alarm", AlarmCommandPath},
{"send an email", EmailCommandPath},
{"", NULL}
};
which will be used as follows:
CommandPath *cPath = NULL;
string input;
getline(cin, i...
Hi Guys,
yesterday I had posted a question: How should I pass a pointer to a function and allocate memory for the passed pointer from inside the called function?
From the answers I got, I was able to understand what mistake I was doing.
I'm facing a new problem now, can anyone help out with this?
I want to dynamically allocate a 2D ar...
I'm making a thread class to use as a wrapper for pthreads. I have a Queue class to use as a queue, but I'm having trouble with it. It seems to allocate and fill the queue struct fine, but when I try to get the data from it, it Seg. faults.
http://pastebin.com/Bquqzxt0 (the printf's are for debugging, both throw seg faults)
edit: the q...
i intend to fill a char-pointer array successively in a for-loop. the content to fill in is a integer so i need to cast. but i didn't get the result i want to..
for (i=0;i<max0;i++){
sprintf(buf, "%d", content[i]);
}
sprintf replaces the hole buf, but i want to append.
for (i=0;i<max0;i++){
buf[i]=(char) contint[i]
}
but th...