Alright, this one's been puzzling me for a bit.
the following function encodes a string into base 64
void Base64Enc(const unsigned char *src, int srclen, unsigned char *dest)
{
static const unsigned char enc[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
unsigned char *cp;
int i;
cp = dest...
I do not understand pointers. Where can I learn more about them?
...
#include <cstring>
int main()
{
char *pName = new char[10];
char dummy[] = "dummy";
strcpy(pName + 0,dummy);//how this is different from -->this works
strcpy(pName[0],dummy);//this one...--> error C2664: 'strcpy' :
//cannot convert parameter 1
//from 'char' to 'c...
#include<stdio.h>
#include<conio.h>
void print(char *arr);
void main()
{
clrscr();
char temp='r';
print(&temp);
getch();
}
void print(char *arr)
{
int arrsz=sizeof(arr);
printf("size is %d",sizeof(arr));
printf("char is %c",arr);
}
Why do I get this output?
size is 1
char is e
Surely it should say cha...
void FileManager::CloseFile(File * const file)
{
for (int i = 0; i < MAX_OPEN_FILES; ++i)
{
if ((_openFiles[i] == file) == true)
{
_openFiles[i] == NULL;
}
}
...
_openFiles is a private member of FileManager and is just an array of File *'s
When the exact same test is performed in the Immediate window i get a result of 1!?!...
Hi,
i need a ptr to a static 2-dimensional array. How is this done?
static uint8_t l_matrix[10][20];
void test(){
uint8_t **matrix_ptr = l_matrix; //wrong idea
}
i dont get it, but all kinds of errors like:
warning: assignment from incompatible pointer type
subscripted value is neither array nor pointer
error: invalid use of f...
Hello:
I'm making a domino game and when the user adds a domino to the left, the domino is added but when the function exits the domino added is GONE.
FYI:
fitxesJoc (Link List) contains the dominoes of
the game and is a pointer passed to the function (so that it lasts all the game)
opcionesCorrectas (Domino) contains the correct cho...
I was wondering how a Garbage Collector can be implemented with C++ full power of pointers arithmetic. Also, In languages like Java, I can not assign literal addresses to references. In C++ it is very flexible.
I believe that C# has both, but again, the unsafe pointer in C# is the responsibility of the programmer.
EITD :: guys, I am as...
I'm writing a small C program to do some number crunching, and it needs to pass around arrays between functions. The functions should accept and return pointers, right?
For example, this (I know it may not be the most efficient thing):
int* reverse(int* l, int len) {
int* reversed = malloc(sizeof(*reversed)*len);
int i, j;
...
I'm writing a simple program. There is only one class in it. There is a private member 'char * number' and two function (there will be more, but first these should work correctly :) ).
The first one should copy the 'source' into 'number' variable (and I suppose somewhere here is the problem):
LongNumber::LongNumber(const char * source ...
I want to do something that seems fairly simple... I get results but the problem is, I have no way to know if the results are correct.
I'm working in C and I have two pointers; I want to print the contents of the pointer. I don't want to dereference the pointer to get the value pointed at, I just want the address that the pointer has st...
Hello,
We have the following code fragment:
char tab[2][3] = {'1', '2', '\0', '3', '4', '\0'};
printf("%s\n", tab);
And I don't understand why we don't get an error / warning in the call to printf. I DO get a warning but not an error, and the program runs fine. It prints '12'.
printf is expecting an argument of type char *, i.e. a po...
class A {
public: int i;
};
A *a = new A();
How to get the address of a->i? I tried &a->i and also &(a->i) but those generate compile time errors:
"left of '.i' must have class/struct/union type"
...
char myData[505][3][50]; //2D array, each 50 chars long
char **tableData[505] = {NULL};
const char* text;
text = sqlite3_column_text(stmt, col_index);
strcpy(myData[row_index][c_index],text);
tableData[row_index] = myData[row_index][c_index]; <--?
I would like to assign the pointer to pointer array tableData to the content o...
Normally when adding sprites to a layer in cocos2d I'd just add a pointer to the layer's interface for each sprite to allow it to be referenced in that layer. However, I'm now using for loops to create an array of sprites:
-(void) make5Gobs
{
Sprite *gobs[5];
for(int i = 0; i < 3; i++)
{
gobs[i] = [Sprite spriteWithFil...
Suppose that I define some class:
class Pixel {
public:
Pixel(){ x=0; y=0;};
int x;
int y;
}
Then write some code using it. Why would I do the following?
Pixel p;
p.x = 2;
p.y = 5;
Coming from a Java world I always write:
Pixel* p = new Pixel();
p->x = 2;
p->y = 5;
They basically do the same thing, right?
O...
When do you and when dont you need the * symbol (which is because in objective-c all variables like NSString are pointer variables)?
For example when do you need to do "NSString *" instead of just "NSString"?
...
Is it possible to remove an array element by a pointer?
Multidimensional array:
$list = array(
1=>array(
2=>array('entry 1'),
3=>array('entry 2')
),
4=>'entry 3',
5=>array(
6=>array('entry 4')
)
);
Reference array:
$refs = array(
1=>&$list[1],
2=>&$list[1][2],
3=>&$li...
If I have an array of char pointers and another static array of characters, how do I assign each element of the array of pointers to each element of a static array?
(Trying to break down a problem into a smaller problem.)
Thanks.
array of pointers array of char
+----+ ...
I'm building a comparator for an assignment, and I'm pulling my hair out because this seems to simple, but I can't figure it out.
This function is giving me trouble:
int compare(Word *a, Word *b)
{
string *aTerm = a->getString();
string *bTerm = b->getString();
return aTerm->compare(bTerm);
}
Word::getString returns a st...