Agni 370 Practically a Master Poster Featured Poster

vector as coolgamer mentioned above is a dynamic array. you can use it to store data.It can grow as per requirement and you dont need to worry about the size at compile time. it's best suited for conditions where you need random search and less of inserts and updates.

example:

vector<int> v;
int i =10;
v.push_back(i);
//fetch an element
cout << v[0] << endl;

when i declare a vector i mention the type of elements it will store, in this case 'int'. then i can insert as many 'int's' into it as needed. if your task requires you to use a vector of Member Pointers then you should declare something like

vector<Member*> v;

and then get pointers to member objects and insert into it.
each value stored in a vector is an element of the vector. its upto you to decide what will be the element in your program.

Agni 370 Practically a Master Poster Featured Poster

or else you can use an array of FILE* if you want to use them elsewhere in the program. or write a structure with elements as FILE* and filename and use an array of that structure.

Agni 370 Practically a Master Poster Featured Poster

you dont need a separate structure for a member_type, use the exisiting structure which coolgamer had suggested and add another field to it.

i think best would be that you try to write some code from whatever you have understood till now and post it, then we can take it from there.

Agni 370 Practically a Master Poster Featured Poster

you could add one more field to the structure which specifies the 'member_type' and write that to your file then when you load the file based on the 'member_type' you can create the correct object type.

Agni 370 Practically a Master Poster Featured Poster

if ( Addition = true) ? or if (Addition == true) ?

Agni 370 Practically a Master Poster Featured Poster

this is much better but unfortunately i could not make out y the update is not happening correctly... my suspicion is on 'seekp' but i have no way to be sure ... we'll have to wait for someone else ....

Agni 370 Practically a Master Poster Featured Poster

Hi,
This code is too difficult to read. Can you please post a well formatted-indented code with code type specified as c++? and also post the entire code including the 'main'. I tried going through this but its just giving me a headache.

Agni 370 Practically a Master Poster Featured Poster

Hi,

has anyone used the mdb debugger in solaris? I need to debug a core file on a client Machine which has neither dbx nor gdb. i could only find mdb, unfortunately i've never used mdb and it's kind of tricky. i dont know if people still use it these days. if anyone is familiar with it then i can poast problems i'm facing after doing a few steps that i read on some articles on net.

Agni 370 Practically a Master Poster Featured Poster

This is my code for a chat client. I create a simple UI with a text box for viewing the chat and an entry widget to write messages. There's a button called 'Connect', when i click this i start a new thread which does the connection and keeps receiving messages n writing them to the text box. The 'run' method also checks the screen state and if it's not in focus or minimized then it plays a sound.
my problem is that i dont want to play a sound but rather toggle the 'title string' or change the color of the root widget, basically somekind of visual indication that a new message has come. i tried a lot of things but as soon i try to do anythin in this thread the application just hangs.

please c the code and suggest something.

from Tkinter import *
import socket
import threading
import tkMessageBox
import winsound
import re
import pdb

#pdb.set_trace()
class myUIChat(Frame,threading.Thread):
    def __init__(self,par,wid,ht):
        Frame.__init__(self,master=par,width=wid,height=ht)
        threading.Thread.__init__(self)
        self.parent = par
        self.threadCount = 1
        self.connect()

    def connectToChat(self):
        try:            
            self.clientSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.clientSocket.connect(('',7500))
            self.connectButton.config(text='Disconnect',command=self.closeConnection)            
            self.startRecvThread()              
        except:
            tkMessageBox.showinfo(message='Server down hai bidu... din bhar bas chatting hi karni hai tumhe')                 
            
    def connect(self):
        self.startChatWindow()    
       
    def startChatWindow(self):
        #draw the chat window
        self.scrollbar = Scrollbar(self)
        self.scrollbar.grid(row=3,column=3)       

        self.connectButton = Button(self,text='Connect To Chat',command=self.connectToChat)
        self.connectButton.grid(row=2,column=2)

        self.textWidget = Text(self,yscrollcommand=self.scrollbar.set)
        self.textWidget.grid(row=3,column=2)
        self.textWidget.bind('<Insert>',self.showWin)
        self.scrollbar.config(command=self.textWidget.yview)
        #self.textWidget.config(state=DISABLED)

        self.entryWidget = Entry(self)
        self.entryWidget.grid(row=5,column=2)
        self.entryWidget.bind('<Return>',self.sendMessage)
        self.entryWidget.focus()

    def showWin(self,event):
        print 'showin'        
                              
    def sendMessage(self,event):
        try:
            self.outMsg = self.entryWidget.get()
            self.clientSocket.send(self.outMsg)
            self.entryWidget.delete(0,END)
        except:            
            tkMessageBox.showinfo(message='kuch gadbad hai.. baad main try karo, …
Agni 370 Practically a Master Poster Featured Poster

use 'strcmp'

Agni 370 Practically a Master Poster Featured Poster

parcel.calculateCost() and box.calculateCost() seems to be the culprits. In the derived class the methods calculateCost returns 'void'.

Agni 370 Practically a Master Poster Featured Poster

you're trying to 'cout' the return value of some method, but the method might be returning 'void'.

Agni 370 Practically a Master Poster Featured Poster

yes you need to make it multi-threaded. Everytime the user clicks on the button it can spawn a new thread which does the work and the button is free for input. i think this code should help you

from Tkinter import *
import threading
import time

class process(threading.Thread):
    def __init__(self):
        threading.Thread.__init__(self)

    def run(self):
        print 'hello'
        time.sleep(60)
        print 'bye'        

#The class process derives from threading.Thread. whenver we say process.start it spawns #a new thread and calls it's 'run' method
def startThread():
    process().start()
    
root = Tk()
frame = Frame(root)
frame.pack()

#when user clicks button it calls 'startThread' command
but = Button(frame,text='start',command=startThread)
but.pack()

text = Text(frame)
text.pack()

root.mainloop()

you'll see that each thread sleeps for a minute but the input button doesn't wait for the output and is ready to take the next input. Once each thread finishes it prints the 'bye' message.

I'm fairly new to multi-threading myself so if you find any issues with this let me know or any doubts.

Agni 370 Practically a Master Poster Featured Poster

>I want it to be infinite, if possible
Do you have infinite storage capacity?

Agni 370 Practically a Master Poster Featured Poster

what is this? what do you want us to do with this? I'm pretty sure this doesn't work.

Agni 370 Practically a Master Poster Featured Poster

It all boils down to understanding how arrays are stored in memory and how we access each element of an array.

arrays are stored sequentially in memory. So lets say you declare and array of 5 integers
int arr[5];
in memory you can imagine it to be 5 cells allocated one after another, each cell big enough to hold an integer. Each of these cells is given a number starting from '0'. Hence to get the value of first element i can say arr[0], for 2nd element arr[1] n so on.

In your code you declare an array of type 'STUDENT'. hence student gives you the value stored in 'i'th location which is of type 'STUDENT'. hence you get the structure, now you access the 'name' attribute of that structure student.name.

Internally accessing an array is done using pointers. Once you understand this you should learn that too.

Agni 370 Practically a Master Poster Featured Poster

Thanks for the links Vijayan. will go through them.

Agni 370 Practically a Master Poster Featured Poster

If fate doesn't make you laugh, then you just don't get the joke.

-"shantaram" by gregory david roberts

Agni 370 Practically a Master Poster Featured Poster

Hi Guys..

I need to know how to debug the 'main' of an exe using dbx. i cant put a 'sleep' and recompile it. For example in windows using visual .Net i can do something like

>devenv /debugexe xyz.exe

This will bring up the exe in debugmode. i need the equivalent of this in dbx. till now i first bring up the process and then attach it using 'attach' command.

Agni 370 Practically a Master Poster Featured Poster

Though i'd like to believe otherwise but i think he's right to a large extent. Even in my own company they are porting the entire product from c++ to java and we have been asked to decide weather we'd like to move to Java or stay in c++ for supporting the old clients. Company is sponsoring java certifications too. I dont feel like moving to Java at all and so damn confused right now. My experience with Java is that it's pretty easy to learn and code. You dont need to worry about pointers and stuff, infact for sometime in between i did code in Java but then just left it completely. C++ is my choice and i hope to stick to it.

Another opinion is that as you move ahead in your career you'd rather be a jack of many trades so that you can handle projects on various technologies.

As of now i dont see any evident shortage of c++ openings atleast here in India.

Agni 370 Practically a Master Poster Featured Poster

You need to give more info dude. As far as usage is concerned just look into any python tutorial on WWW

Agni 370 Practically a Master Poster Featured Poster

thanks Edwards, that makes sense. Need to understand the virtual base classes more.

>Change the private constructor into a public constructor..

yes but then we wouldn't have faced the problem and wouldn't have come to know all this. it was just something i was trying to do.

Agni 370 Practically a Master Poster Featured Poster

i think its more because of the keyword 'virtual', just try and remove that and it compiles and excutes fine. Normally the class Second wil call the ctor of class First and then class First will call the ctor of Lock so i dont need to make 'Second' a friend of 'Lock'. but when i derive from the class 'Lock' virtually this doesnt happen.

Alex Edwards commented: Yeah I completely forgot that it's the First classes responsibility to call the private Constructor, not the Second +1
Agni 370 Practically a Master Poster Featured Poster
#include <iostream>

using namespace std;

class Lock
{
	friend class First;
	private:
		Lock()
		{
		}
};

class First : virtual public Lock
{
	public:
		void function()
		{
			cout << "function1" << endl;
		}
};

class Second: public First
{
	public:
		void function2()
		{
			cout << "function2" << endl;
		}
};

int main()
{
	First f;
	f.function();

	Second s;
	s.function2();
}

Error:
classVirtDer.cpp(39) : error C2248: 'Lock::Lock' : cannot access private member declared in class 'Lock'
classVirtDer.cpp(9) : see declaration of 'Lock::Lock'
classVirtDer.cpp(6) : see declaration of 'Lock'
This diagnostic occurred in the compiler generated function 'Second::Second'

But when i remove the class Second, it works fine. Can someone explain?

Agni 370 Practically a Master Poster Featured Poster

yes 'tee' is a unix command that splits the pipe into stdout and files. Probably i should have specified that these will not work for windows.

Agni 370 Practically a Master Poster Featured Poster

You could do something like

system("cc -c test.cpp | tee out.log")

or

system("cc -c test.cpp >> out.log")
Agni 370 Practically a Master Poster Featured Poster

i dont think you should assign a char inside double quotes. Try

play[2] = '*'
if (play[2] == '*')

Agni 370 Practically a Master Poster Featured Poster

From the package Manager you can install 'DrPython' . It's a neat IDE for writing/debuggin/executing python scripts.

Agni 370 Practically a Master Poster Featured Poster

Use the 'sleep' function available in 'time' module.

Agni 370 Practically a Master Poster Featured Poster

The size of the array has to be known at compile time. If it has to be decided at run-time please use dynamic arrays. When you used #Define the size was known at compile time hence it worked.

Agni 370 Practically a Master Poster Featured Poster

hex2bin[h] will give the value for the key 'h'.
i executed each statement separately, without declaring the dictionary and the output will make things very clear to you

>>number=1000
>>for h in '%X'%number:
        print h

3
E
8

now you can see that 'h' gets values 3,E,8. All these values are 'key's in the dictionary hex2bin. lets see what are the values for each key

hex2bin[3] = 0011
hex2bin[E] = 1110
hex2bin[8] = 1000

0011 1110 1000

hence 'join' is joining these 3 strings and stripping(lstrip) the leading 0's hence the output

1111101000

sneekula commented: good explanation +4
Agni 370 Practically a Master Poster Featured Poster

Can you post the code if possible. also a sample file or a snip of the data in file.

Agni 370 Practically a Master Poster Featured Poster

Algo will be:

1>divide the number by 10.
2>print the remainder or store it in an array.
3>assign the quotient as the original number and loop steps 1-2-3 till quotient it less than 10
4>print the last digit or store it.

Now you should have each digit.

Agni 370 Practically a Master Poster Featured Poster

There's a thread in this forum, 'c/c++ faqs and practice problems', right on top, you can try to solve the problems mentioned in that.

Agni 370 Practically a Master Poster Featured Poster

One more way is to use a single dimension array. You can as easily take all the inputs from the users and then declare a single dimension array dynamically, size would the product of the the dimensions. and then while accessing the elements you can use pointer arithmetic.
something like:

//taking inputs as rows n cols
                int* arr = new int[rows * cols];
	int k = 0;
	for (int i=0;i<rows;i++)
	{
		for (int j=0;j<cols;j++)
		{
			arr[i*cols+j] = k++;
		}
	}
                // print the values row wise
	for (int i=0;i<rows;i++)
	{

		for (int j=0;j<cols;j++)
		{
			cout << arr[i*cols+j];
		}
		cout << "change of row" << endl;
	}

You can easily extend this for 3D arrays now.

Agni 370 Practically a Master Poster Featured Poster

OK my bad.. i didnt see that "Status" is declared right above in the class defintion and it's an Enum. Please ignore my post. Though you can still read about 'operator overloading' if you feel like.

sorry for the confusion

Agni 370 Practically a Master Poster Featured Poster

Where is 'Status' defined?? .. Basically 'Status' is not a native Datatype of c++ and so it doesnt have a predefined '==' operator for it. So you need to overload the particular operator before you do something like Status == xxx.

Read more about the topic "Operator Overloading" and you will understand.

Agni 370 Practically a Master Poster Featured Poster

Hi,

I have 2 modules, grepforapp.py and myApp.py. Basically i'm trying to make a 'search' utility. myApp makes the UI with one textbox for taking input, start button and a list box which displays the file names where the pattern was found.
grepforApp walks through the dir tree and searches the pattern in each file. In my previous code i used to read and store everything and then would display the results in one shot. Then i changed the code to call the grepforapp.search in a loop and try to display the results as they come for each dir. but this is not happening. If you see the code i'm doing a ListBox.Append in a loop but still the final result is shown in one shot and not in steps. Can anyone see what's wrong with the code?

myApp module

import wx
import grepforapp
import os
import pdb
import time

#pdb.set_trace()

class myApp(wx.Frame):
	def __init__(self,parent,id,title):
		wx.Frame.__init__(self,parent,id,title)	
		self.tc1 = None
		self.Show()	
		
	def addButton(self,ID,butStr,coord):
		wx.Button(self,ID,butStr,coord)
		self.Bind(wx.EVT_BUTTON,self.addStaticBox,id=ID)
		
	def addStaticBox(self,event):		
		superDict = {}		
		tc2 = None
		tc2 = wx.ListBox(self, 26, (5,80), (350, 150),style=wx.LB_SINGLE)
		tc2.SetForegroundColour('#RRGGBB')		
		pattern = self.tc1.GetValue()
		superDict = {}
		if pattern != '':
			for roots,dirs,files in os.walk(os.getcwd()):
				myFileList = []
				fileList = []
				superDict.clear()
				myFileList = self.getFileList(files)
				superDict = grepforapp.searchPattern(pattern,1,myFileList,roots)
#				for key in superDict.keys():
#					print key
				fileList = superDict.keys()
				tc2.AppendItems(fileList)	
				time.sleep(10)
	
	def getFileList(self,files):
#		print roots,dirs,files
		i = 0
		i = len(files)
		searchAll = 1
#		print i
		myFileList = []            
		for j in range(i): …
Agni 370 Practically a Master Poster Featured Poster

and also when you have a funtion like

string send(string aaa)
{
       hr_str=aaa;
       //cout<<"\nin Fun"<<hr_str;
    
}

that defines a return type as 'string' and returns nothing.

Agni 370 Practically a Master Poster Featured Poster

This code is not even compiling. If you can post the correct-compiling code i can try to find the problem.

Agni 370 Practically a Master Poster Featured Poster

d.size[] should be d.size()

Agni 370 Practically a Master Poster Featured Poster

dude for that i'll have to understand the equation and i dont want to tell you something that gives a wrong result. what i was trying to explain to you is how to pass a vector to a function or a vector of vector to a function. You might have to go through that and see how you can modify your code.

Agni 370 Practically a Master Poster Featured Poster

value = distance(trajectories[x]);

This is incorrect. trajectories[x] is not of type 'Paths' its of type 'Dots'. Remember when you say [x] you are passing the element at that location and the types are different. If you want to pass trajectories[x] then in the defintion you need to take them in the same type something like 'distance(Dots d)'

Agni 370 Practically a Master Poster Featured Poster

if you want to pass a 'Paths' type to 'distance' you simply have to call like this

distance(trajectories)

since trajectories is of type 'Paths', in the definition you will say

double distance(Paths trajectory){}
Agni 370 Practically a Master Poster Featured Poster

And please check for succesful allocation and if yes then dont fgt to free this block of memory once you'r done

Agni 370 Practically a Master Poster Featured Poster

the example is not too easy to read and follow, i just gave a generic answer. If you need to keep a counter of sorts in each class then using a static varible is ok.

Agni 370 Practically a Master Poster Featured Poster

you can put the sumAll function in baseClass. The printAll can be made virtual and also moved to base class. This way you can sum up the values in base(since both are int's) and then print the correct message out. i'm not sure why you're using so many static's and how you are initialising the values etc.

Agni 370 Practically a Master Poster Featured Poster

worked like a charm... thanks a lot Wayne ... i didnt know about this 'readlines' function.

Agni 370 Practically a Master Poster Featured Poster

malloc allocates memory and returns a pointer to the beginning of that block of memory. You need to assign it to some pointer not an object as you are doing here. Change that to pointer and it should work.

i couldnt really understand your 2nd qs, would be helpful if you attached the files also.

Agni 370 Practically a Master Poster Featured Poster

Hi,

When i search for a pattern in a file how do i get the line and line#? basically i want to replicate the 'grep' command functionality. Now i can easily say whether the pattern exists or not using re.search funtion but i'm not able to print that particular line and line#. are there any functions in re module for that?