The following code manipulates pointers to point at the same location; I'm puzzled about why when I ran the code, the output didn't show value coinciding.
#include "stdio.h"
main()
{
int i=3,*x;
float j=1.5,*y;
char k='c',*z;
x=&i;
y=&j;
z=&k;
printf("\nAddress of x= %u",x);
printf("\nAddress of y= %u",y);
printf...
I've recently updated to a testing distribution, which is now using GCC 4.4.3. Now I've set everything up, I've returned to coding and have built my project and I get one of these horrible messages:
*** glibc detected *** ./boxyseq: free(): invalid pointer: 0x0000000001d873e8 ***
I absolutely know what is wrong here, but was rather con...
How can i write an if statement which tells to the program if the pointer is assigned or not?
WRONG example
if (*badpdr[0]==0);
??
...
Hi,
I am working on some C code.
There is a function like this;
void Get(double x_la[],
double y_la[],
double z_la[])
in the function body, for some other reasons I create;
double (*la)[3];
As far as I understood, x_la, y_la and z_la are pointers of the type double.
I need to "connect" the pointers involved in "la" wiht the p...
Hello to everyone!!
I am trying to print the MAC address by using ether_ntoa. When i try to do
printf("MAC (src): %s\n",ether_ntoa((struct ether_addr *)&eheader->ether_shost));
I get a segmentation fault, so I have come up with two different approaches:
This is the snippet code nº1:
struct ether_header *eheader;
char *p;
...
p = et...
#include <iostream>
typedef struct _person
{
std::string name;
unsigned int age;
}Person;
int main()
{
Person *pMe = new Person;
pMe->age = 10;
pMe->name = "Larson";
std::cout << "Me " << (*pMe).age << " " << (*pMe).name.c_str() << std::endl;
return 0;
}
Consider the above code. The members of the struct...
I am trying to find the location of an element in the array.
I have tried to use this code i generated
for(i=0;i<10;i++)
{
if (strcmp(temp[0],varptr[i])==0) j=i;
}
varptr is a pointer which points to array var[11][10] and it is by the definition *varptr[11][10]. I have assigned strings to var[i] and i want to get the "i" n...
I'm reading through the LZMA SDK source code and noticed that they assign pointers passed into a method to themselves - example (from the SDK, C/Util/7z/7zAlloc.c):
void *SzAlloc(void *p, size_t size)
{
p = p; <-- !
if (size == 0)
return 0;
#ifdef _SZ_ALLOC_DEBUG
fprintf(stderr, "\nAlloc %10d bytes; count = %10d", size, ...
Hi
coming from this question "What does (int (*)[])var1 stand for?" I tried to access the result of the cast like a multidimensional array. But I get following error: "assignment from incompatible pointer type" followed by a segmentation fault. I tried also some other variations, but none of them worked. How can I access the elements in...
Hi, I'm learning C++. I have a simple class named GameContext:
class GameContext {
public:
GameContext(World world);
virtual ~GameContext();
};
To initialize a GameContext object, I need a World object.
Should the GameContext constructur take a pointer to a World object (World*), the address to a World object (&...
Hi,
If I have some stupid code like this:
int nBlah = 123;
int* pnBlah = &nBlah;
pnBlah += 80000;
*pnBlah = 65;
Can I change another app's memory?
You have explained me this is evil, I know. But I was just interested.
And this isn't something to simply try. I don't know what would happen.
Thanks
...
Hello folks,
This one is probably very simple, but I can't seem to get it working.
I have this very simple snippet of code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char buf[100];
char *p = buf;
strcpy(p, "Test string");
printf("%s\n", *p);
}
Which causes a segmentation fault when I run it. GDB outputs:
...
for example suppose that some k which is arbitrary number=2 k=2 then there is code in c
int wordcomp(char *p, char *q) {
int n = k;
for ( ; *p == *q ; p++, q++) {
if ( *p==0 && --n == 0 )
return 0;
}
return *p - *q;
}
please explain me what does this code do? also what means *p-*q?and also how im...
void my_cool_function()
{
obj_scene_data scene;
obj_scene_data *scene_ptr = &scene;
parse_obj_scene(scene_ptr, "test.txt");
}
Why would I ever create a pointer to a local variable as above if I can just do
void my_cool_function()
{
obj_scene_data scene;
parse_obj_scene(&scene, "test.txt");
}
Just in case it's ...
Hi
I am getting this message on emulator when I run my android project:
The application MediaPlayerDemo_Video.java (process com.android.MediaPlayerDemo_Video) has stopped unexpectedly. Please try again
I am trying to run the MediaPlayerDemo_Video.java given in ApiDemos in the Samples given on developer.android.com.
The code is ...
I have a table of structures and this structures are 2 dimentional table of constants.
can you teach me on how to get the values in the table of constants.
(note following is just example)
typedef struct
{
unsigned char ** Type1;
unsigned char ** Type2;
} Formula;
typedef struct
{
Formula tformula[size];
} table;...
On Learn C++, they wrote this to free memory:
int *pnValue = new int; // dynamically allocate an integer
*pnValue = 7; // assign 7 to this integer
delete pnValue;
pnValue = 0;
My question is: "Is the last statement needed to free the memory correctly, completly?"
I thought that the pointer *pnValue was still on the stack and new does...
I am writing a WPF application that allows the user to draw over the entire screen when the right mouse button is held down. I use a full screen transparent overlay form to achieve this, however, as I draw lines with the mouse, what's happening is that the portion of my window that contains the line is becoming visible (as expected). The...
Sorry if this question has been asked before. On my search through SO I didn't find one that asked what I wanted to know.
Basically, when I have this:
typedef struct node
{
int data;
node *node;
} *head;
and do node *newItem = new node;
I am under the impression that I am declaring and reserving space, but not defining, a p...
I'm playing with C and I've run into this error:
#include <stdio.h>
int main ()
{
char* foo;
scanf("%s", foo);
printf("entered %s", foo);
return 0;
}
scanf takes pointer, foo is pointer, yet I get bus error. How can I make it work?
...