pointers

Linked Lists, Assigning char array [C]

Hi all. I've got the task of making a car rental program, which uses linked lists to control what cars are available for rent, are rented, or are in repair. The 'car' is a structure, and so is the rented list, available list, and repair list. Heres my current issue. If the user wants to make a new car available, we must add it to our l...

c++ vector How to change internal pointer

hi guys, I would like to serialize vector. And dunno how to change pointer of vector.. To make it simple let's say I have a vector smt like: vector<char> v; And I have this pointer: char* c = { 'v', 'e', 'c', 't', 'o', 'r' }; And I would like my vector v's internal pointer points my char* c: &v[0] -> c How can I adjust vector...

XCode compiler doesn't set my variable (and pointer) initial value to 0 or nil!

Hi, sthis is very annoying, since now my values are stored as if they contain somethin by default (like in c). All my OO stuff are now broken since my delegate are always somethin. I was wonderin why XCode do this to me, since by default XCode always set the variable value to 0 or nil. So if i do NSArray* anArray; and then NSLog(%@"...

Pointer not initializing with a struct as a parameter. Access violation writing location 0x00000010.

The struct looks like this: template <class Node_entry> Node<Node_entry>::Node(Node_entry item, Node *add_on) { entry = item; next = add_on; } And the *new_rear pointer does not get initialized, but &item is filled with user input. Error_code Extended_queue::append(const Queue_entry &item) { Node<Queue_entry> *new_...

Queue appending more then one entry.

I keep getting the first entry appended 4 times instead of one time.. when I append my first entry to the Queue it appends it 4 times..I thought this might be the problem..but it looks like it isn't. I can't find where the problem is.. I also created a print function for the nodes, and it showes that there are 4 of the same entries in t...

C++ call back system. Pointers to member functions.

Hi, Im trying to create a call back by passing a pointer to member functions but am running into all types of issues. How can i go about implementing such a thing template<class T> class A{ void (T::*callBackFunction)(int); public: void addCallBack(void (T::*callBackFunction)(int)){ void (T::*callBackFunction...

Objective C / Object Orientated Pointers

Hello world.. I have been playing with objective C a little and am finding it a great language.. Coming from C# i found pointers a little hard but now i understand the concept and how to use them.. ie: MyObject* x = [[myObject alloc] callinitializer]; which create a new object on the heap and a pointer on the stack.. but can someb...

Visual Basic 2010: How do I reference one of many objects through an additional object? (Pointer-like behaviour?)

Hi, I am writing an application in Visual Basic 2010 Express. I have two objects of a class from a driver DLL that is provided to me. They have some of their own subroutines that I'd like to call, and I'd like an easy way to toggle between them. Instead of writing a whole bunch of code like this: selected = x ... If selected = x then ...

Const-correctness and immutable allocated objects

During a recent discussion (see comments to this answer), R.. recommended to never create aliases for pointer-to-const types as you won't be able to deallocate the referenced objects easily in a conforming C program (remember: free() takes a non-const pointer argument and C99 6.3.2.3 only allows conversions from non-qualified to qualifi...

bool from a struct lead to "error: expression must have class type"

I have a struct defined as struct sData{ idx * id; int * stime; bool * result; unsigned int N; }; Then the code that uses it in numeric compute(numeric e, sData swabs){ numeric cache=0.0; int sid=0; while(sid<swabs.N){ if(swab.result[sid]) cache += log(e); else cache += log(1.0-e); sid += 1; } retu...

using malloc() for double pointers

Hi there, a malloc question. First, I generate some strings. And second, I allocate none-space for copying pointers which point to those strings. At this moment the program should probably crash, since I ve tried to copy those pointers to nowhere, but it doesn’t crash. How is it possible? Any comments would be appreciated. #include <...

Pointers pointing to invalid location.

#include <stdio.h> int main(void) { int x = 1000; char *ptr = &x; printf("%d\n",*ptr); return 0; } Output: -24 /*In gcc 4.4.3 in Ubuntu 10.04 OS*/ With a warning: initialization from incompatible pointer type What I think if the base type of the pointer were of int type then it would have retrieved 4 bytes from the ...

Check for null pointer

Hi, I'm building a iphone app and using c++ and am having trouble checking if a pointer is null. IMyInterface* myInterface; if ( !myInterface ){ //doesn't work myInterfacee->doSometing(); } if ( myInterface != 0 ) { //doesn't work myInterfacee->doSometing(); } if ( myInterface !...

C Homework; 1st Pointer Assignment

This code is supposed to skip white space and return one word at a time. A couple of questions on this code: When the code gets to the *word++=c; line I get a core dump. Have I written this line correctly? and is return correct. And Do I need to somehow allocate memory to store the word? //get_word int get_word(char *word,int lim){ ...

what is different between char* t=new char and char* t=new char[10];

Possible Duplicate: What's the difference between new char[10] and new char(10) what is different between char* t1=new char and char* t2=new char[10]; both allocate memory and t1[100]='m' and t2[100]='m' is correct for them -----------after edit: but why we can use t1[100] if t1 is dynamically allocated char not ar...

What EXACTLY is meant by "de-referencing a NULL pointer"?

I ama complete novice to C, and during my university work I've come across comments in code that often refer to de-referencing a NULL pointer. I do have a background in C#, I've been getting by that this might be similar to a "NullReferenceException" that you get in .Net, but now I am having serious doubts. Can someone please explai...

C pointer on a pointer : unused variable

Hello, I was just doing my first app in C and i have this warning (edited) : unused variable pp int compteur = 1; int *p = &compteur; int **pp = &p; I was just trying to make pp pointing on the adress of the variable p Forgive me if that's a stupid question, but in my book they don't talk about pointers on pointer. Thanks ...

Copying alhpanumeric chars in C

Hey, this should be pretty simple but getting stuck. Have a char array of text, want to store the alphanumeric lowercase value in a pointer array. ie mystr should point to a char[] of "50sometexthere" char[] myline = " 50 Some Text Here "; char *mystr = (char *)malloc(128 * sizeof(char)); char *tmp = myline; while (*tmp != '\0'){ i...

C Program terminating with -1 (0xFFFFFFFF), seemingly no reason?

#include <stdio.h> typedef struct pduct {char name[20]; int price; int stock;} PRODUCT; void init(PRODUCT * product) { printf("What is the name of the product: "); fgets(product->name, 20, stdin); printf("DEBUG: Did it get written...: %s", product->name); printf("What is th...

Incompatible Pointer Type Error

Hey everyone, I am getting a compile error in my code, and I cannot figure out what to do. Here's the block: #include <stdio.h> #include <string.h> /* * Function to return index at which team ID input is stored */ int getIndex(char* id, char* idList[][50]) { int k; for (k=0; k<50; k++) { if (strcmp(id,idList[k])==0...