hi there, I'm coding in windows, c++, but when I traslate my code to ubuntu, g++, I get this error: [B]lvalue required as left operand of assigment[/B] This is the line where I get the error: [COLOR="Red"][/COLOR][CODE]&*raiz=&*p;[/CODE] What could be the problem? *raiz and *p are pointers to an avl structure: [CODE] typedef struct nodo{ int dato; int fe; int color; struct nodo *izq; struct nodo *der; struct nodo *padre; }nodo; typedef struct nodo *avl; [/CODE] and this is the method where I have the problem: [CODE] void RSD(avl *raiz){ avl *p; p=new avl; *p=NULL; avl *q; q=new avl; *q=NULL; …

Member Avatar
Member Avatar
+0 forum 11

I just started learning how to use pointer array and i'm trying out examples to know more about them but i get confused with them easily. So, I tried to do a simple arithmetic calculation using a pointer array. The user will input 2 string variables for addition. I then reverse the string variable. int i = 0; int j; char temp; j = s1.length(); while (i < j) { temp = s1[i]; s1[i] = s1[j]; s1[j] = temp; i++; j--; } I tried to convert 2 string variables i have into a integer pointer array before adding them together …

Member Avatar
Member Avatar
+0 forum 3

I have been struggling with this for two days now, with no luck. I have a **C** `char` array `char myArray[] = "Hello World";` I also have a pointer to pointer to *char* `char **ptr;` So I want to somehow store `myArray` to `ptr` or somehow convert `myArray`into pointer to pointer to *char* . Any suggestions of how I can achieve this.

Member Avatar
Member Avatar
+0 forum 4

Hi All, I wanted to know in below code snippet what will be impact if m_singleObject is declared as a weak_ptr. Usaually we peform lock on weak_ptr and convert the same in to the shared pointer and then return the same to GetInstance() function. static std::shared_ptr<singleType> shareObject = m_singleObject.lock why can't we use direcltly shared_ptr for m_singleObject instead of by declaring weak_ptr and peforming the lock on the same as i did in below code snippet. #include <iostream> #include <memory> using namespace std; class a { public: void fun(){cout<<"show";} }; template<class singleType> class Singleton { public: static std::shared_ptr<singleType> GetInstance(); private: …

Member Avatar
Member Avatar
+0 forum 2

Hi All, I just want to know whether use of shared_ptr is justified in below code here or do i need to use unique_ptr instead of shared_ptr? #include <iostream> #include <memory> using namespace std; class a { int a1 ,b; public: a(int x=0,int y=0):a1(x),b(y){} void fun1() {cout<<a1;cout<<b;} }; class b { private: std::shared_ptr <a> p; public: b (int x=0, int y=0):p( new a (x,y)){} b ( const b &obj):p(new a(*obj.p)){} void fun2(){p->fun1();} }; int main() { b obj1(10,20); b obj2(obj1); obj2.fun2(); return 1; }

Member Avatar
Member Avatar
+0 forum 3

Hi all, I was wondering how to access individual elements in the below case: char *three=(char*){'2','5','8'}; If the assignment were like this: char *three="258"; it can be accessed with three[0],three[1].....etc. How to access in the first case?

Member Avatar
Member Avatar
+0 forum 1

Hello All, I am having trouble looping through a 2D array in C++ (should be very easy, but I am just starting C++). At the current moment I have this class file #include "Cube.h" #include <freeglut.h> #include <stdio.h> Cube::Cube(int cx, int cy, int cz , int cubeWidth) { int p[][3] = { { cx, cy, cz }, { cx, cy-cubeWidth, cz }, { cx + cubeWidth, cy - cubeWidth, cz },{cx + cubeWidth, cy, cz}, { cx, cy, cz - cubeWidth }, { cx, cy-cubeWidth, cz - cubeWidth }, { cx+cubeWidth, cy-cubeWidth, cz - cubeWidth }, { cx+cubeWidth, cy, cz …

Member Avatar
Member Avatar
+0 forum 1

I am having a problem with reading input data after checking a position marker in the data file. The code that does the reading follows: fip = fopen("fprmf.txt","r"); . . . strcpy(passw,"P7"); fscanf(fip, "%3s", ckod); /* card # 164 */ fprintf(ff16,"\n\n%12s%12s\n", "card# 164 :", "Password "); printf("passwd is %s\n", ckod); if(strcmp(passw,ckod)!=0) { printf("\n%64s\n%80s\n", "E R R O R !", "Password is incorrect. Please resubmit."); exit(164); } /***** Cards 165 - 174 *****/ fprintf(ff16, "\nLIST OF SOLVENCY SURCHARGE RATES\n"); fscanf(fip, "%5.3f", &solvpctchkinitial); fscanf(fip, "%5.3f", &solvpctchkmaximum); fprintf(ff16, "INITIAL PERCENTAGE = %5.3f, MAXIMUM PERCENTAGE = %5.3f\n", solvpctchkinitial, solvpctchkmaximum); surchargeCheckPercent = solvpctchkinitial; for(i=1;i<=18; i++) …

Member Avatar
Member Avatar
+0 forum 1

I wrote this program that get words from user and if it was entered already it will print you loose but when I the first code crashs but the second code works! why the first code is crashs? #include <stdio.h> #include <string.h> int getword(char *word); int find(char * words[], int i); char *words[100]; int main() { int i = 0; while (i < 100) { printf("enter your word"); get_word(words[i]); if (find(words, i)) { printf("you lose"); exit(1); } i++; } printf("no body wins"); } int get_word(char *word) { word= (char *)malloc(sizeof(char)*100); scanf("%s", word); } int find(char * words[],int i) { int …

Member Avatar
Member Avatar
+0 forum 2

Hi again everybody. I know there are some references to this kind of thing around the web but none of them are simple enough for me to understand. In my code below, I am trying to initialize a function pointer with a class member function but I'm not sure I understand how. For simplicity my function pointer "myfunction" is to be initialized with myclass::class_function. How do I do this? Thank you. #include <iostream> #include <cstdlib> using namespace std; class myclass { public: void class_function() { cout << "Class Function Called" << endl; } }; int main() { void(*myfunction)(); myclass cls; …

Member Avatar
Member Avatar
+0 forum 2

All of us started from being a rookie, and I'm one of those rookies who are new in this course. Maybe its time for you to share your expertise unto the newbies? Hope anyone might help me willingly in my program.Here's the problem: Use Pointers and Functions: Ask a user wether (+), (-), (*), or (/) is to be executed, After choosing the operation, ask the user how many operands will it use. Display the correct corresponding output. Example: Chose an Operation: * Number of Operands: 3 Enter 1st Operand: 2 Enter 2nd Operand: 1 Enter 3rd Operand: 3 The …

Member Avatar
Member Avatar
+0 forum 4

quick question how can I work around this char * dat = "08/11/2014"; char test[10] = dat; I need to be able to take a string and put it into an array of chars, how can i do this?

Member Avatar
Member Avatar
+0 forum 1

Hi guys, I want to access the element of structure from structure pointer using indexing for below code snippet. apart from this I also would like to know is there any way to find the type of member variable of structure on run time. #include <stdio.h> #include <assert.h> #include <stdlib.h> #include <string.h> #include<stdint.h> typedef struct Node{ uint32_t var1; uint16_t var2; uint32_t var3; uint8_t *var4; uint8_t var5[257]; }node_t; void initialize_field(node_t *field_val ) { field_val = (node_t*)malloc(sizeof(node_t)); assert(field_val != NULL); field_val->var1=0x22; field_val->var2= 2023; field_val->var3 =8132014; strcpy(field_val->var4,"RRAA:1001"); strcpy(field_val->var5,"ABC"); } int main() { node_t *field_val=NULL; initialize_field(field_val); //field_val[index] doesn't seems to be possible return 1; …

Member Avatar
Member Avatar
+0 forum 1

This snippet defines a function [icode]mousepos()[/icode] which gets the mouse position on the screen. The package python-xlib is required.

Member Avatar
Member Avatar
+1 forum 7

#include <memory> #include <deque> void MyFunc { std::deque< std::shared_ptr< Sprite* > > SpriteList; func_to_fill_deque( SpriteList ); for( auto i = SpriteList.begin(), end = SpriteList.end(); i != end; i++ ) { SpriteList[ i ]->spriteFunc(); // doesn't work SpriteList.at( i )->spriteFunc(); // also doesn't work } } void func_to_fill_deque( std::deque< std::shared_ptr< Sprite* > >& list ) { ptr = new Sprite( filename ); list.push_back( std::make_shared< Sprite* >( ptr ) ); } When I try SpriteList[ i ] I get a red squiggle under the first '[' with the msg "No operator matches these operands" Trying SpriteList.at( i ) gives a red squiggle …

Member Avatar
Member Avatar
+0 forum 2

Hello, I have learnt a few assembly languages (MIPS/x86/ARM/MIX) and I have a question about the call stack. Each of those languages uses a different method for subroutine linkage, and the way I learnt them was not conducive to recursion. Granted, if I continue reading my copy of The Art of Computer Programming Knuth claims that he will explain how to do it, however the way he writes I will have to understand everything before that point which will be awhile. I am impatient. As such I would like to know, in a generic language, how does one implement proper …

Member Avatar
+0 forum 0

Hi, I created a structure Vector and implement some functions to make the new defined type (vector) dynamically allocated and resized (inspired from the C++ implementation of the dynamic arrays : vector). I need to assign a structure to every vector element but I am not sure that I am doing it right: here is the structure that I ve defined: ************************************************** ********** typedef struct { void** mem; // to make this parametrizable I want the void* to point to a Structure (referenced with * a pointer) unsigned long elems; unsigned long elemsize; //element size unsigned long capelems; //capacity of …

Member Avatar
Member Avatar
+0 forum 6

i'm not sure if a pointer can do the job of an iterator, or otherwise, or they are different things?

Member Avatar
Member Avatar
+0 forum 3

So decided I should switch to VS13 for the added benefits. Copied the cold, transfered the files, alls good right? Wrong. Actually its not that bad. Just one main problem. `ltm` See this fella? This is the one guy that is standing in the way of me and the debachury that i am programing. He is the name of my pointer for the time aspect of my program. so... `ltm->tm_mon;` He and his buddies are throughout my 500+ line program that functioned fine in Bloodshed. The problem? VS13 doesnt play friendly with localtime (they dated once and had a fall …

Member Avatar
Member Avatar
+0 forum 1

Hi, While executing below code i am getting error like "memory clobbered before allocated block" and due to this assignment is not happening. could you let me know what can be reason for the same. I do understand it is not good to use raw pointer but in current scenario i don't have other than any option. #include<iostream.h> using namespace std; class Derived1 { int *m_p; public: Derived1 (int *m_p):m_p(m_p){}; Derived1& operator =( const Derived1 &obj); void show()const {cout<<"integer address="<<(void*)m_p<<endl; cout<<"integer="<<*m_p<<endl; } ~Derived1(){ delete m_p; } }; Derived1& Derived1::operator=(const Derived1 &obj) { if (this!=&obj) { cout<<"We are Here"; int *orig …

Member Avatar
Member Avatar
+0 forum 4

![6b87dfe9bac7df6c309f7266d28a4ad0](/attachments/small/4/6b87dfe9bac7df6c309f7266d28a4ad0.JPG "align-left") i am reading "pointers in c by naveen toppo" .According to him program crashes when it encounter int y=*ptr; i dont understand why it should crash?i think its correct. *ptr gives int value. please refer attachement.

Member Avatar
Member Avatar
+0 forum 1

i was reading a book and came across this line "C++ matches a pointer of any other type with type void * and prints a numeric representation of the address. If you want the address of the string, you have to type cast it to another type," please any one could explain this with the help of an example.

Member Avatar
Member Avatar
+0 forum 1

in the code const char* buf what is the constant? The pointer or buf?

Member Avatar
Member Avatar
+0 forum 5

I'm trying to zoom in on a Picturebox when scrolling the mousewheel, the code below zooms in on the image only to the center of the image, not at the current cursor position. How would I fix this? PictureBox1.Size = New System.Drawing.Size(PictureBox1.Width + e.Delta / 1, PictureBox1.Height + e.Delta / 1) PictureBox1.Location = New Point(Control.MousePosition.X - PictureBox1.Width / 2, Control.MousePosition.Y - PictureBox1.Height / 2)

Member Avatar
Member Avatar
+0 forum 6

here is question: Write a function that accepts an array of integers and its size as arguments. The function should create a new array that is one element larger than the argument array. The first element of the new array should be set to 0. Element 0 of the argument array should be copied to element 1 of the new array, element 1 of the argument array should be copied to element 2 of the new array, and so forth. The function should return a pointer to the new array. here is what i got so far. I am so …

Member Avatar
Member Avatar
+0 forum 4

Hi All, I got this code from a forum & tried it on g++/Linux. In the code below i put NULL to a pointer variable but didnt get any errors. #include <iostream> using namespace std; class A { private: int _dmember; public: void func() { cout<<"Inside A!! "<<endl; cout<<_dmember; // } }; int main () { A *a=NULL; a->func(); // prints "Inside A!!!" return 1; } can someone please explain this to me ?

Member Avatar
Member Avatar
+0 forum 5

Hello, I came across a strange pointer (in my opinion): `void *(*foo)(int *);` Why are so many stars there? It was explained like: "...read inside-out; notice that the innermost element of the expression is *foo, and that otherwise it looks like a normal function declaration. *foo should refer to a function that returns a void * and takes an int *. Consequently, foo is a pointer to just such a function." So I understood that foo is a pointer to a void function f(int). I tried to code this but failed with `error: invalid conversion from 'void (*)(int*)' to 'void* …

Member Avatar
Member Avatar
+0 forum 7

Hello all, I am stuck with a nullpointerException at line 41 and 60.Can someone please help me out.any kind of help will be appreciated. Thanks import javax.swing.*; import javax.swing.event.*; import java.awt.Color; import java.awt.*; class calenders extends JFrame { int i=0; int j=0; int k=0; JFrame jf; FlowLayout fl; JPanel jp[]; JButton jb []; JButton jb3[]; Button b[]; calenders() { jf=new JFrame ("Happy 2014 :-)"); fl=new FlowLayout(); b=new Button[12]; jp=new JPanel[12]; String days[]={"Sun", "Mon","Tue", "Wed", "Thurs", "Fri", "Sat"}; String months[]={"Jan", "Feb","March", "Apr", "May", "July", "August","september","october","november","december"}; //JButton jb1=new JButton("Previous"); //JButton jb2=new JButton("Next"); jb3=new JButton[7]; String dates[]={"1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20", "21","22","23","24","25","26","27","28","29","30","31"}; jb=new JButton[31]; Color colors[]={Color.blue, Color.yellow, …

Member Avatar
Member Avatar
+0 forum 8

How can I create an array of pointer using **P and point it to NULL? Let's say I have coded as below . struct s { float a ; char x ; } ; s **p ; p = new ( s * [10] ) ; Now I want to make some of them as NULL p[0] = NULL ; p[5] = NULL ; If I simply coded as above then it gives me a warning and also the above method is wrong in how it makes the variable NULL. So how to do I do this?

Member Avatar
Member Avatar
+0 forum 1

Hi, i'm trying to make 3 different input scenarios using argv. In the code below where there is just one input so when it is argv[0] the calendar for this month comes up, when it is argv[1] so when there are two inputs, it will printout the calendar for the whole year and when it is argv[2] it will printout the calendar for a specific year and month. but i'm getting this warning error at (int year = argv[1]) and (int month = argv[1]) and (int year = argv[2]) and i'm not sure where to start fixing it: int main(int …

Member Avatar
Member Avatar
+0 forum 2

The End.