Search Results

Search found 23792 results on 952 pages for 'void pointers'.

Page 26/952 | < Previous Page | 22 23 24 25 26 27 28 29 30 31 32 33  | Next Page >

  • Loop with pointer arithmetic refuse to stay within boundary in C. Gives me segfault.

    - by Fred
    Hi have made this function which is made to replicate an error that I can't get past. It looks like this: void enumerate(double *c, int size){ while(c < &c[size]){ printf("%lf\n", *c); c++; } } I have added some printf's in there and it gives me: Adressof c: 0x100100080, Adressof c + size: 0x1001000a8 I then also print the address of c for each iteration of the loop, it reaches 0x1001000a8 but continues past this point even though the condition should be false as far as I can tell until I get a segfault. If anyone can spot the problem, please tell me, I have been staring at this for a while now. Thanks.

    Read the article

  • Can someone explain how pointer to pointer works?

    - by user3549560
    I don't really understand how the pointer to pointer works. Any way to do the same work without using pointer to pointer? struct customer{ char name[20]; char surname[20]; int code; float money; }; typedef struct customer customer; void inserts(customer **tmp) { *tmp = (customer*)malloc(sizeof(customer)); puts("Give me a customer name, surname code and money"); scanf("%s %s %d %f", (*tmp)->name, (*tmp)->surname, &(*tmp)->code,&(*tmp)->money); }

    Read the article

  • C++ function-pointer and inheritance

    - by pingvinus
    In parent class I have function, that operates under an array of functions, declared in child-class, number of functions for every child-class may vary. But since every function uses some object-variables, I can't declare them as static. I've try to do something like this: class A { public: typedef int (A::*func)(); func * fs; void f() { /*call functions from this->fs*/ } }; class B : public A { public: int smth; B(int smth) { this->smth = smth; this->fs = new func[1]; fs[0] = &B::f; } int f() { return smth + 1; } }; But, obviously it doesn't work. Any suggestions?

    Read the article

  • Dynamic allocated array is not freed

    - by Stefano
    I'm using the code above to dynamically allocate an array, do some work inside the function, return an element of the array and free the memory outside of the function. But when I try to deallocate the array it doesn't free the memory and I have a memory leak. The debugger pointed to the myArray variable shows me the error CXX0030. Why? struct MYSTRUCT { char *myvariable1; int myvariable2; char *myvariable2; .... }; void MyClass::MyFunction1() { MYSTRUCT *myArray= NULL; MYSTRUCT *myElement = this->MyFunction2(myArray); ... delete [] myArray; } MYSTRUCT* MyClass::MyFunction2(MYSTRUCT *array) { array = (MYSTRUCT*)operator new(bytesLength); ... return array[X]; }

    Read the article

  • Why does this C++ code result in a segmentation fault?

    - by user69514
    I keep getting a segmentation fault when the readAuthor() method is called. Does anybody know why this happens? I am supposed to use dynamic arrays, I know this would be so easy if I was using static array. #include <iostream> #include <string> #include <cstring> #include <cstdlib> using namespace std; /** declare arrays **/ int* isbnArr = new int[25]; char* authorArr = new char[25]; char* publisherArr = new char[25]; char* titleArr = new char[25]; int* editionArr = new int[25]; int* yearArr = new int[25]; int* pagesArr = new int[25]; float* retailPriceArr = new float[25]; float* discountedPriceArr = new float[25]; int* stockArr = new int[25]; /** function prototypes **/ int readIsbn(); char* readAuthor(); char* readPublisher(); char* readTitle(); int readEdition(); int readYear(); int readPages(); float readMsrp(); float readDiscountedPrice(); int readStockAmount(); void readonebook(int* isbn, char* author, char* title, char* publisher, int* edition, int* year, int* pages, float* msrp, float* discounted, int* inventory); int main() { bool stop = false; //flag when to stop loop int ind = 0; //index for current book while( !stop ){ cout << "Add book: press A: "; cout << "another thing here "; char choice; cin >> choice; if( choice == 'a' || choice == 'A' ){ readonebook(&isbnArr[ind], &authorArr[ind], &titleArr[ind], &publisherArr[ind], &editionArr[ind], &yearArr[ind], &pagesArr[ind], &retailPriceArr[ind], &discountedPriceArr[ind], &stockArr[ind]); test(&authorArr[ind]); ind++; } } return 0; } /** define functions **/ int readIsbn(){ int isbn; cout << "ISBN: "; cin >> isbn; return isbn; } char* readAuthor(){ char* author; cout << "Author: "; cin >> author; return author; } char* readPublisher(){ char* publisher = NULL; cout << "Publisher: "; cin >> publisher; return publisher; } char* readTitle(){ char* title = NULL; cout << "Title: "; cin >> title; return title; } int readEdition(){ int edition; cout << "Edition: "; cin >> edition; return edition; } int readYear(){ int year; cout << "Year: "; cin >> year; return year; } int readPages(){ int pages; cout << "Pages: "; cin >> pages; return pages; } float readMsrp(){ float price; cout << "Retail Price: "; cin >> price; return price; } float readDiscountedPrice(){ float price; cout << "Discounted Price: "; cin >> price; return price; } int readStockAmount(){ int amount; cout << "Stock Amount: "; cin >> amount; return amount; } void readonebook(int* isbn, char* author, char* title, char* publisher, int* edition, int* year, int* pages, float* msrp, float* discounted, int* inventory){ *isbn = readIsbn(); author = readAuthor(); title = readTitle(); publisher = readPublisher(); *edition = readEdition(); *year = readYear(); *pages = readPages(); *msrp = readMsrp(); *discounted = readDiscountedPrice(); *inventory = readStockAmount(); }

    Read the article

  • The unary increment operator in pointer arithmetic

    - by RhymesWithDuck
    Hello, this is my first post. I have this function for reversing a string in C that I found. void reverse(char* c) { if (*c != 0) { reverse(c + 1); } printf("%c",*c); } It works fine but if I replace: reverse(c + 1); with: reverse(++c); the first character of the original string is truncated. My question is why would are the statements not equivalent in this instance? Thanks

    Read the article

  • Freeing a character pointer returns error

    - by Kraffs
    I'm trying to free a character pointer after having used it but it returns a strange error. The error says: "_CrtDbgREport: String too long or IO Error" The debugger itself returns no errors while compiling. The code currently looks like this: void RespondToUser(SOCKET client, SOCKET server) { char buffer[80]; char *temp = malloc(_scprintf("HTTP/1.1 200 OK\r\n%s\r\nServer: %s\r\nConnection: close\r\n\r\nHi!", buffer, SERVER_NAME)); sprintf(temp, "HTTP/1.1 200 OK\r\n%s\r\nServer: %s\r\nConnection: close\r\n\r\nHi!", buffer, SERVER_NAME); send(client, temp, strlen(temp), 0); closesocket(client); free(temp); ListenToUsers(server); } The problem only occurs when I try to free the temp pointer from the memory and not otherwise. What might be causing this?

    Read the article

  • collect string in loop and printout all the string outside loop

    - by user1508163
    I'm newbie here and there is some question that I want have some lesson from you guys. For example: #include <stdio.h> #include<stdlib.h> #include<ctype.h> void main() { char name[51],selection; do { printf("Enter name: "); fflush(stdin); gets(name); printf("Enter another name?(Y/N)"); scanf("%c",&selection); selection=toupper(selection); }while (selection=='Y'); //I want to printout the entered name here but dunno the coding printf("END\n"); system("pause"); } As I know when the loops perform will overwrite the variable then how I perform a coding that will printout all the name user entered? I have already ask my tutor and he is ask me to use pointer, can anyone guide me in this case?

    Read the article

  • Reading function pointer syntax

    - by bobobobo
    Everytime I look at a C function pointer, my eyes glaze over. I can't read them. From here, here are 2 examples of function pointer TYPEDEFS: typedef int (*AddFunc)(int,int); typedef void (*FunctionFunc)(); Now I'm used to something like: typedef vector<int> VectorOfInts ; Which I read as typedef vector<int> /* as */ VectorOfInts ; But I can't read the above 2 typedefs. The bracketing and the asterisk placement, it's just not logical. Why is the * beside the word AddFunc..?

    Read the article

  • C++: Print only one char

    - by Martijn Courteaux
    Hi, When I read one char* from std::cin and I want to write it to std::cout, it prints until it finds a \0 in memory. So what did was: char c; cin >> c; char* pChar = &c; pChar++; *pChar = '\0'; println(&c); // My own method: void println(char * str) { cout << str << endl; } But I don't think this is a safe action. Is there a safer way to do this?

    Read the article

  • Add 64 bit offset to a pointer

    - by Novox
    In F#, there's the NativePtr module, but it seems to only support 32 bit offsets for its’ add/get/set functions, just like System.IntPtr does. Is there a way to add a 64 bit offset to a native pointer (nativeptr<'a) in F#? Of course I could convert all addresses to 64 bit integers, do normal integer operations and then convert the result again to nativeptr<'a, but this would cost additional add and imul instructions. I really want the AGUs to perform the address calculations. For instance, using unsafe in C# you could do something like void* ptr = Marshal.AllocHGlobal(...).ToPointer(); int64 offset = ...; T* newAddr = (T*)ptr + offset; // T has to be an unmanaged type Well actually you can't, because there is no "unmanaged" constraint for type parameters, but at least you can do general pointer arithmetic in a non-generic way. In F# we finally got the unmanaged constraint; but how do I do the pointer arithmetic?

    Read the article

  • Converting a pointer for a base class into an inherited class

    - by Shawn B
    Hey, I'm working on a small roguelike game, and for any object/"thing" that is not a part of the map is based off an XEntity class. There are several classes that depend on it, such as XPlayer, XItem, and XMonster. My problem is, that I want to convert a pointer from XEntity to XItem when I know that an object is in item. The sample code I am using to pick up an item is this, it is when a different entity picks up an item it is standing over. void XEntity::PickupItem() { XEntity *Ent = MapList; // Start of a linked list while(true) { if(Ent == NULL) { break; } if(Ent->Flags & ENT_ITEM) { Ent->RemoveEntity(); // Unlink from the map's linked list XItem *Item = Ent // Problem is here, type-safety // Code to link into inventory is here break; } Ent = Ent->MapList; } } My first thought was to create a method in XEntity that returns itself as an XItem pointer, but it creates circular dependencies that are unresolvable. I'm pretty stumped about this one. Any help is greatly appreciated.

    Read the article

  • Simple dynamic memory allocation bug.

    - by M4design
    I'm sure you (pros) can identify the bug's' in my code, I also would appreciate any other comments on my code. BTW, the code crashes after I run it. #include <stdlib.h> #include <stdio.h> #include <stdbool.h> typedef struct { int x; int y; } Location; typedef struct { bool walkable; unsigned char walked; // number of times walked upon } Cell; typedef struct { char name[40]; // Name of maze Cell **grid; // 2D array of cells int rows; // Number of rows int cols; // Number of columns Location entrance; } Maze; Maze *maz_new() { int i = 0; Maze *mazPtr = (Maze *)malloc(sizeof (Maze)); if(!mazPtr) { puts("The memory couldn't be initilised, Press ENTER to exit"); getchar(); exit(-1); } else { // allocating memory for the grid mazPtr->grid = (Cell **) malloc((sizeof (Cell)) * (mazPtr->rows)); for(i = 0; i < mazPtr->rows; i++) mazPtr->grid[i] = (Cell *) malloc((sizeof (Cell)) * (mazPtr->cols)); } return mazPtr; } void maz_delete(Maze *maz) { int i = 0; if (maz != NULL) { for(i = 0; i < maz->rows; i++) free(maz->grid[i]); free(maz->grid); } } int main() { Maze *ptr = maz_new(); maz_delete(ptr); getchar(); return 0; } Thanks in advance.

    Read the article

  • Remove pointer object whose reference is mantained in three different lists

    - by brainydexter
    I am not sure how to approach this problem: 'Player' class mantains a list of Bullet* objects: class Player { protected: std::list< Bullet* > m_pBullet_list; } When the player fires a Bullet, it is added to this list. Also, inside the constructor of bullet, a reference of the same object is updated in CollisionMgr, where CollisionMgr also mantains a list of Bullet*. Bullet::Bullet(GameGL*a_pGameGL, Player*a_pPlayer) : GameObject( a_pGameGL ) { m_pPlayer = a_pPlayer; m_pGameGL->GetCollisionMgr()->AddBullet(this); } class CollisionMgr { void AddBullet(Bullet* a_pBullet); protected: std::list< Bullet*> m_BulletPList; } In CollisionMgr.Update(); based on some conditions, I populate class Cell which again contain a list of Bullet*. Finally, certain conditions qualify a Bullet to be deleted. Now, these conditions are tested upon while iterating through a Cell's list. So, if I have to delete the Bullet object, from all these places, how should I do it so that there are no more dangling references to it? std::list< Bullet*>::iterator bullet_it; for( bullet_it = (a_pCell->m_BulletPList).begin(); bullet_it != (a_pCell->m_BulletPList).end(); bullet_it++) { bool l_Bullet_trash = false; Bullet* bullet1 = *bullet_it; // conditions would set this to true if ( l_Bullet_Trash ) // TrashBullet( bullet1 ); continue; } Also, I was reading about list::remove, and it mentions that it calls the destructor of the object we are trying to delete. Given this info, if I delete from one list, the object does not exist, but the list would still contain a reference to it..How do I handle all these problems ? Can someone please help me here ? Thanks PS: If you want me to post more code or provide explanation, please do let me know.

    Read the article

  • Incompatible types when assigning to type 'struct compartido'

    - by user1660559
    I have one problem with this code. I should create one structure and share it across 5 new process created from the father: #include <stdio.h> #include <stdlib.h> #include <sys/wait.h> #include <unistd.h> #include <sys/types.h> #include <sys/ipc.h> #include <sys/shm.h> #include <sys/sem.h> #include <time.h> struct compartido { int pid1, pid2, pid3, pid4, pid5; int propietario; int contador; int pidpadre; }; struct compartido var; int main(int argc, char *argv[]) { key_t llave1,llavesem; int idmem,idsem; llave1=ftok("/tmp",'a'); idmem=shmget(llave1,sizeof(int),IPC_CREAT|0600); if (idmem==-1) { perror ("shmget"); return 1; } var=shmat(idmem,0,0); /*This line is giving the error*/ /*rest of the code*/ } The exact error is giving is: error: incompatible types when assigning to type 'struct compartido' from type 'void *' I need to put this structure in the shared variable to be able to see and modify all those data from the 6 process (5 children and the father). What I'm doing bad? Thanks in advance and best regards,

    Read the article

  • How can I pass a const array or a variable array to a function in C?

    - by CSharperWithJava
    I have a simple function Bar that uses a set of values from a data set that is passed in in the form of an Array of data structures. The data can come from two sources: a constant initialized array of default values, or a dynamically updated cache. The calling function determines which data is used and should be passed to Bar. Bar doesn't need to edit any of the data and in fact should never do so. How should I declare Bar's data parameter so that I can provide data from either set? union Foo { long _long; int _int; } static const Foo DEFAULTS[8] = {1,10,100,1000,10000,100000,1000000,10000000}; static Foo Cache[8] = {0}; void Bar(Foo* dataSet, int len);//example function prototype Note, this is C, NOT C++ if that makes a difference; Edit Oh, one more thing. When I use the example prototype I get a type qualifier mismatch warning, (because I'm passing a mutable reference to a const array?). What do I have to change for that?

    Read the article

  • C++ arrays as parameters, subscript vs. pointer

    - by awshepard
    Alright, I'm guessing this is an easy question, so I'll take the knocks, but I'm not finding what I need on google or SO. I'd like to create an array in one place, and populate it inside a different function. I define a function: void someFunction(double results[]) { for (int i = 0; i<100; ++i) { for (int n = 0; n<16; ++n) //note this iteration limit { results[n] += i * n; } } } That's an approximation to what my code is doing, but regardless, shouldn't be running into any overflow or out of bounds issues or anything. I generate an array: double result[16]; for(int i = 0; i<16; i++) { result[i] = -1; } then I want to pass it to someFunction someFunction(result); When I set breakpoints and step through the code, upon entering someFunction, results is set to the same address as result, and the value there is -1.000000 as expected. However, when I start iterating through the loop, results[n] doesn't seem to resolve to *(results+n) or *(results+n*sizeof(double)), it just seems to resolve to *(results). What I end up with is that instead of populating my result array, I just get one value. What am I doing wrong?

    Read the article

  • C++, using one byte to store two variables

    - by 2di
    Hi All I am working on representation of the chess board, and I am planning to store it in 32 bytes array, where each byte will be used to store two pieces. (That way only 4 bits are needed per piece) Doing it in that way, results in a overhead for accessing particular index of the board. Do you think that, this code can be optimised or completely different method of accessing indexes can be used? c++ char getPosition(unsigned char* c, int index){ //moving pointer c+=(index>>1); //odd number if (index & 1){ //taking right part return *c & 0xF; }else { //taking left part return *c>>4; } } void setValue(unsigned char* board, char value, int index){ //moving pointer board+=(index>>1); //odd number if (index & 1){ //replace right part //save left value only 4 bits *board = (*board & 0xF0) + value; }else { //replacing left part *board = (*board & 0xF) + (value<<4); } } int main() { char* c = (char*)malloc(32); for (int i = 0; i < 64 ; i++){ setValue((unsigned char*)c, i % 8,i); } for (int i = 0; i < 64 ; i++){ cout<<(int)getPosition((unsigned char*)c, i)<<" "; if (((i+1) % 8 == 0) && (i > 0)){ cout<<endl; } } return 0; } I am equally interested in your opinions regarding chess representations, and optimisation of the method above, as a stand alone problem. Thanks a lot

    Read the article

  • Writing a printList method for a Scheme interpreter in C

    - by Rehan Rasool
    I am new to C and working on making an interpreter for Scheme. I am trying to get a suitable printList method to traverse through the structure. The program takes in an input like: (a (b c)) and internally represent it as: [""][ ][ ]--> [""][ ][/] | | ["A"][/][/] [""][ ][ ]--> [""][ ][/] | | ["B"][/][/] ["C"][/][/] Right now, I just want the program to take in the input, make the appropriate cell structure internally and print out the cell structure, thereby getting (a (b c)) at the end. Here is my struct: typedef struct conscell *List; struct conscell { char symbol; struct conscell *first; struct conscell *rest; }; void printList(char token[20]){ List current = S_Expression(token, 0); printf("("); printf("First Value? %c \n", current->first->symbol); printf("Second value? %c \n", current->rest->first->first->symbol); printf("Third value? %c \n", current->rest->first->rest->first->symbol); printf(")"); } In the main method, I get the first token and call: printList(token); I tested the values again for the sublists and I think it is working. However, I will need a method to traverse through the whole structure. Please look at my printList code again. The print calls are what I have to type, to manually get the (a (b c)) list values. So I get this output: First value? a First value? b First value? c It is what I want, but I want a method to do it using a loop, no matter how complex the structure is, also adding brackets where appropriate, so in the end, I should get: (a (b c)) which is the same as the input. Can anyone please help me with this?

    Read the article

  • pointer, malloc and char in C

    - by user2534078
    im trying to copy a const char array to some place in the memory and point to it . lets say im defining this var under the main prog : char *p = NULL; and sending it to a function with a string : myFunc(&p, "Hello"); now i want that at the end of this function the pointer will point to the letter H but if i puts() it, it will print Hello . here is what i tried to do : void myFunc(char** ptr , const char strng[] ) { *ptr=(char *) malloc(sizeof(strng)); char * tmp=*ptr; int i=0; while (1) { *ptr[i]=strng[i]; if (strng[i]=='\0') break; i++; } *ptr=tmp; } i know its a rubbish now, but i would like to understand how to do it right, my idea was to allocate the needed memory, copy a char and move forward with the pointer, etc.. also i tried to make the ptr argument byreferenec (like &ptr) but with no success due to a problem with the lvalue and rvalue . the only thing is changeable for me is the function, and i would like not to use strings, but chars as this is and exercise . thanks for any help in advance.

    Read the article

  • casting char[][] to char** causes segfault?

    - by Earlz
    Ok my C is a bit rusty but I figured I'd make my next(small) project in C so I could polish back up on it and less than 20 lines in I already have a seg fault. This is my complete code: #define ROWS 4 #define COLS 4 char main_map[ROWS][COLS+1]={ "a.bb", "a.c.", "adc.", ".dc."}; void print_map(char** map){ int i; for(i=0;i<ROWS;i++){ puts(map[i]); //segfault here } } int main(){ print_map(main_map); //if I comment out this line it will work. puts(main_map[3]); return 0; } I am completely confused as to how this is causing a segfault. What is happening when casting from [][] to **!? That is the only warning I get. rushhour.c:23:3: warning: passing argument 1 of ‘print_map’ from incompatible pointer type rushhour.c:13:7: note: expected ‘char **’ but argument is of type ‘char (*)[5]’ Are [][] and ** really not compatible pointer types? They seem like they are just syntax to me.

    Read the article

  • glibc detected ./.a.out: free(): invalid pointer

    - by ExtremeBlue
    typedef struct _PERSON { size_t age; unsigned char* name; }PERSON; int init(PERSON** person) { (* person) = (PERSON *) malloc(sizeof(struct _PERSON)); (* person)->age = 1; (* person)->name = (unsigned char *) malloc(sizeof(4)); (* person)->name = "NAME"; return 0; } void close(PERSON** person) { (* person)->age = 0; if((* person)->name != NULL) { free((* person)->name); } if((* person) != NULL) { free((* person)); } } int main(int argc, char* argv[]) { PERSON* p; init(&p); printf("%d\t%s\n", (int) p->age, p->name); close(&p); return 0; } 1 NAME *** glibc detected *** ./a.out: free(): invalid pointer: 0x000000000040079c *** ======= Backtrace: ========= /lib/libc.so.6(+0x774b6)[0x7fa9027054b6] /lib/libc.so.6(cfree+0x73)[0x7fa90270bc83] ./a.out(close+0x3d)[0x400651] ./a.out[0x40069f] /lib/libc.so.6(__libc_start_main+0xfe)[0x7fa9026acd8e] ./a.out[0x4004f9] ... 7fa8fc000000-7fa8fc021000 rw-p 00000000 00:00 0 7fa8fc021000-7fa900000000 ---p 00000000 00:00 0 7fa902478000-7fa90248d000 r-xp 00000000 08:12 23068732 /lib/libgcc_s.so.1 7fa90248d000-7fa90268c000 ---p 00015000 08:12 23068732 /lib/libgcc_s.so.1 7fa90268c000-7fa90268d000 r--p 00014000 08:12 23068732 /lib/libgcc_s.so.1 7fa90268d000-7fa90268e000 rw-p 00015000 08:12 23068732 /lib/libgcc_s.so.1 7fa90268e000-7fa902808000 r-xp 00000000 08:12 23068970 /lib/libc-2.12.1.so 7fa902808000-7fa902a07000 ---p 0017a000 08:12 23068970 /lib/libc-2.12.1.so 7fa902a07000-7fa902a0b000 r--p 00179000 08:12 23068970 /lib/libc-2.12.1.so 7fa902a0b000-7fa902a0c000 rw-p 0017d000 08:12 23068970 /lib/libc-2.12.1.so 7fa902a0c000-7fa902a11000 rw-p 00000000 00:00 0 7fa902a11000-7fa902a31000 r-xp 00000000 08:12 23068966 /lib/ld-2.12.1.so 7fa902c25000-7fa902c28000 rw-p 00000000 00:00 0 7fa902c2e000-7fa902c31000 rw-p 00000000 00:00 0 7fa902c31000-7fa902c32000 r--p 00020000 08:12 23068966 /lib/ld-2.12.1.so 7fa902c32000-7fa902c33000 rw-p 00021000 08:12 23068966 /lib/ld-2.12.1.so 7fa902c33000-7fa902c34000 rw-p 00000000 00:00 0 7fff442d5000-7fff442f6000 rw-p 00000000 00:00 0 [stack] 7fff44308000-7fff44309000 r-xp 00000000 00:00 0 [vdso] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall] Aborted

    Read the article

  • why no implicit conversion from pointer to reference to const pointer.

    - by user316606
    I'll illustrate my question with code: #include <iostream> void PrintInt(const unsigned char*& ptr) { int data = 0; ::memcpy(&data, ptr, sizeof(data)); // advance the pointer reference. ptr += sizeof(data); std::cout << std::hex << data << " " << std::endl; } int main(int, char**) { unsigned char buffer[] = { 0x11, 0x11, 0x11, 0x11, 0x22, 0x22, 0x22, 0x22, }; /* const */ unsigned char* ptr = buffer; PrintInt(ptr); // error C2664: ... PrintInt(ptr); // error C2664: ... return 0; } When I run this code (in VS2008) I get this: error C2664: 'PrintInt' : cannot convert parameter 1 from 'unsigned char *' to 'const unsigned char *&'. If I uncomment the "const" comment it works fine. However shouldn't pointer implicitly convert into const pointer and then reference be taken? Am I wrong in expecting this to work? Thanks!

    Read the article

  • Pointer mysteriously moves

    - by Armen Ablak
    Hi, I have this code for Node rotation and in a line which is marked something happens and I don't really know what and why :). //Test case 30 \ 16 / 29 RotationRight(node->mParent); //call template<class T> void SplayTree<T>::RotationRight(SplayNode<T> *&node) const { SplayNode<T> *left = node->mLeft; SplayNode<T> *parent = node->mParent; node->mLeft = left->mRight; if(left->HasRight()) left->mRight->mParent = node; left->mRight = node; //node in this line points to 0x00445198 {30} left->mParent = node->mParent; //and in this line it points to 0x00444fb8 {16} (node, not node->mParent) node->mParent = left; node = left; } Well, left-mParent points to node also, so I basically do node = node-mParent. The problem is I can't find a work around - how to unpin in from node and change it's pointing address without changing it's.

    Read the article

  • segmentation fault when using pointer to pointer

    - by user3697730
    I had been trying to use a pointer to pointer in a function,but is seems that I am not doing the memory allocation correctly... My code is: #include<stdio.h> #include<math.h> #include<ctype.h> #include<stdlib.h> #include<string.h> struct list{ int data; struct list *next; }; void abc (struct list **l,struct list **l2) { *l2=NULL; l2=(struct list**)malloc( sizeof(struct list*)); (*l)->data=12; printf("%d",(*l)->data); (*l2)->next=*l2; } int main() { struct list *l,*l2; abc(&l,&l2); system("pause"); return(0); } This code compiles,but I cannot run thw program..I get a segmentation fault..What should I do?Any help would be appreciated!

    Read the article

< Previous Page | 22 23 24 25 26 27 28 29 30 31 32 33  | Next Page >