|
|
|
Hi Mila025
thank you for link but is there any way to enumerate links
I think that is't not possible.
Thanks
|
|
|
|
|
Hi
One of my friends is getting a strange problem with his code in c++. He has stored some integer values in an array. That array is declared in a class as its member variable.
In a function before printing this array using cout, he wrote the following statement.
cout<<"DAY\tBreak up\tBuying Price\tSelling Price\tGain/Loss\n";
We saw it in Debugger mode that when above statement executes, all values in that array are changed and some garbage values are displayed.
Please can you tell me why this is happening?
Thank you.
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
|
Thank you for your responce. Here is the code
cout<<"DAY\tBreak up\tBuying Price\tSelling Price\tGain/Loss"<<endl;<br />
for(;curr->next!=&head;curr=curr->next)<br />
{<br />
for(;curr->next->array[i].day_number!=-1;i++)<br />
{<br />
cout<<curr->next->array[i].day_number<<"\t"<br />
<<curr->next->array[i].break_up<<"\t"<br />
<<curr->next->array[i].buying_price<<"\t"<br />
<<curr->next->array[i].selling_price<<"\t"<br />
<<curr->next->array[i].capital_gain<<endl;<br />
}<br />
}
I tried this code after omitting the first cout line. but in inner for loop before printing the values again it changes the array contents.
How it is possible?
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
Aqueel wrote: cout<<"DAY\tBreak up\tBuying Price\tSelling Price\tGain/Loss\n";
Use endl instead of \n .
"Let us be thankful for the fools. But for them the rest of us could not succeed." - Mark Twain
"There is no death, only a change of worlds." - Native American Proverb
|
|
|
|
|
problem still remains the same
in this block of code if i perform a very very simple output operation (cout<<"Hello"<
|
|
|
|
|
Here is the whole code u can copy past into your browser and run it
Note
file inpu.txt has the following format
B 100 20
B 20 24
B 200 36
S 150 30
//code begins from here
#include<iostream.h>
#include<fstream.h>
//*******************************************************************
struct SDATA
{
int day_number;
int break_up;
int buying_price;
int selling_price;
int capital_gain;
};
//*******************************************************************
class QNode
{
friend class Queue;
private:
QNode* next;
int day;
int shares;
int price;
QNode(){next=NULL;}
};
//*******************************************************************
class LLNode
{
friend class LList;
friend class Queue;
friend void main();
private:
LLNode* prev;
LLNode* next;
SDATA array[10];
LLNode()
{
prev=NULL;
next=NULL;
for(int i=0;i<10;i++)
{
array[i].day_number=-1;
array[i].break_up=-1;
array[i].buying_price=-1;
array[i].selling_price=-1;
array[i].capital_gain=-1;
}
}
};
//*******************************************************************
class Queue
{
private:
QNode* front;
QNode* rear;
public:
Queue(){front=rear=NULL;};
bool Enqueue(ifstream&);
bool Dqueue(LLNode*, int, int&);
void dis();
};
//*******************************************************************
class LList
{
friend void main();
private:
LLNode head;
public:
LList()
{
head.next=&head;
head.prev=&head;
};
bool add(ifstream&, Queue);
void Display();
};
int dy=1;
//*******************************************************************
//*******************************************************************
bool Queue::Enqueue(ifstream& fin)
{
int shs;
int pr;
fin>>shs;
fin>>pr;
fin.get();
QNode* temp=new QNode();
temp->day=dy;
temp->price=pr;
temp->shares=shs;
if(front==NULL)
{
front=temp;
rear=temp;
rear->next=NULL;
return true;
}
else
{
rear->next=temp;
rear=rear->next;
rear->next=NULL;
return true;
}
delete temp;
}
//*******************************************************************
void Queue::dis()
{
QNode* curr;
curr=front;
int dy,pr,sh;
for(;curr!=NULL;curr=curr->next)
{
dy=curr->day;
pr=curr->price;
sh=curr->shares;
cout<<dy<<" "<<pr<<"="" "<<sh<<endl;
="" }
="" cout<<endl;
}
="" ********************************************************************
bool="" llist::add(ifstream&="" fin,="" queue="" q)
{
="" int="" sell_shares;
="" sell_price;
="" tot="0;
" llnode="" temp;
="" fin="">>sell_shares;
fin>>sell_price;
fin.get();
q.Dqueue(&temp,sell_shares,tot);
for(;tot>=0;tot--)
{
temp.array[tot].selling_price=sell_price;
temp.array[tot].capital_gain=(temp.array[tot].break_up*(sell_price-temp.array[tot].buying_price));
//******************
/*mret->array[tot].day_number=temp.array[tot].day_number;
mret->array[tot].buying_price=temp.array[tot].buying_price;
mret->array[tot].selling_price=temp.array[tot].selling_price;
mret->array[tot].break_up=temp.array[tot].break_up;
mret->array[tot].capital_gain=temp.array[tot].capital_gain;*/
}
LLNode* curr;
curr=&head;
while(curr->next!=&head)
curr=curr->next;
temp.next=curr;
temp.prev=curr->prev;
curr->prev->next=&temp;
curr->prev=&temp;
//************************************************************
{
curr=&head;
cout<<"DAY\tBreak up\tBuying Price\tSelling Price\tGain/Loss\n";
for(;curr->next!=&head;curr=curr->next)
{
for(int i=0;temp.array[i].day_number!=-1;i++)
{
cout<<temp.array[i].day_number<<"\t"
<<temp.array[i].break_up<<"\t"
="" <<temp.array[i].buying_price<<"\t"
="" <<temp.array[i].selling_price<<"\t"
="" <<temp.array[i].capital_gain<<endl;
="" }
=""
="" return="" false;
}
="" ********************************************************************
bool="" queue::dqueue(llnode*="" temp,int="" sell_shares,="" int&="" ret)
{
="" int="" sum="0;
" qnode*="" curr;
="" curr="front;
" count="sell_shares;
" for(int="" i="0;i<10&&curr!=NULL;i++)
" {
="">shares;
curr=curr->next;
}
curr=front;
if(sell_shares>sum)
{
cout<<"\nYOU ARE TRYING TO SELL SHARES OF MORE"<<endl;
cout<<"than="" last="" 10="" days..."<<endl;
="" return="" false;
="" }
="" else
="" {
=""
="" if(front="=NULL)" for(ret="0;count">0;ret++)
{
if(count<front->shares)
{
temp->array[ret].day_number=front->day;
temp->array[ret].buying_price=front->price;
temp->array[ret].break_up=count;
front->shares=front->shares-count;
count=0;
}
else if(sell_shares>=front->shares)
{
temp->array[ret].day_number=front->day;
temp->array[ret].buying_price=front->price;
temp->array[ret].break_up=front->shares;
count=count-front->shares;
front=front->next;
delete curr;
curr=front;
}
}
ret--;
return true;
}
}
}
//********************************************************************
void LList::Display()
{
LLNode* curr;
curr=&head;
int i=0;
cout<<"DAY\tBreak up\tBuying Price\tSelling Price\tGain/Loss"<<endl;
for(;curr-="">next!=&head;curr=curr->next)
{
for(;curr->next->array[i].day_number!=-1;i++)
{
cout<<curr->next->array[i].day_number<<"\t"
<<curr->next->array[i].buying_price<<"\t"
<<curr->next->array[i].break_up<<"\t"
<<curr->next->array[i].selling_price<<"\t"
<<curr->next->array[i].capital_gain<<endl;
}
=""
}
="" ********************************************************************
void="" main()
{
="" llnode="" temp;
="" queue="" q;
="" llist="" l;
="" char="" op;
="" ifstream="" fin;
="" fin.open("input.txt",ios::in);
="" fin="">>op;
while(!(fin.eof()))
{
if(op=='B')
{
for(;op=='B'&&(!fin.eof());)
{
Q.Enqueue(fin);
fin>>op;
dy++;
}
}
else if(op=='S')
{
for(;op=='S'&&(!fin.eof());)
{
L.add(fin,Q);
dy++;
fin>>op;
}
}
}
//Q.dis();
L.Display();
}
We Believe in Excellence
www.aqueelmirza.cjb.net
|
|
|
|
|
Strange. It should not happen this way.
Problem might lie before the cout statement.
As you said even if you write cout<<"Hello" it overwrites the array.
I would suggest to do a stepwise debug.
1) comment out all the array allocation and file reading part.
2) just main() -> and cout<<"Hello"
3) check if this works.
4) if it does then uncomment file readin part.
5) if tht works then problem lies somewhere in the array allocation part.
Hope this helps.
|
|
|
|
|
Hi all,
In my MDI application, I have 10 tool bars. I have a menu to select them. If it is visible, its menu item would be checked. I need to save the position of those tool bars when I exit the application. Next time I should be able to get toolbars, only which were selected earlier. Hope it's like persistent window concept. But I don't know how to make it possible for Toolbars.
If anybody could suggest me a path, it would be greatly appreciated.
Thanks in advance,
Sarvan AL
|
|
|
|
|
#ifdef EXPCLASS_EXPORTS
#define EXPCLASS_API __declspec(dllexport)
#else
#define EXPCLASS_API __declspec(dllimport)
#endif
// This class is exported from the EXPCLASS.dll
class EXPCLASS_API CEXPCLASS {
public:
CEXPCLASS(void);
char * CEXPMethod(char * plaintext , char * key);
// TODO: add your methods here.
};
How do i dynamically acces method export in CLASS?
CODE USED TO ACCESS METHOD EXPORT IN CLASS
hDLL = LoadLibrary("EXPCLASS.dll");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"CEXPMethod");
if (lpfnDllFunc1 ==NULL)
{
// handle the error
FreeLibrary(hDLL);
}
else
{
strResult = lpfnDllFunc1("killer" ,"strikes HERE");
}
}
for thendral
-- modified at 6:54 Thursday 20th April, 2006
|
|
|
|
|
|
Hi naveen !
can u advise what exactly i need to do ?
Use this API to get the address of a function that returns an instance of the class that you wish to access dynamically.
For eg:
The function will be something like this...
void* FUNC_EXPORT CreateInstance()
{ return static_cast< void*> (new SomeClass);
}
Use GetProcAddress to get the address of this function
for thendral
|
|
|
|
|
instead of returning the void* u can return the pointer to the class
say
SomeClass* FUNC_EXPORT CreateInstance()
{ return static_cast< void*> (new SomeClass);
}
them u can access the functions of that clas using the pointer obtained..
nave
|
|
|
|
|
Iam not in control of the situation.
Can i have a sample code that achieves it?
class __declspec(dllexport) MyClass
{
public:
static char* LSGDecrypt(const char* key,const char* hex);
static char* LSGEncrypt(const char* key,const char* source);
}
The above class is export in a dll .
So should i add new function to the dll ?
Iam about access a static function
So is that required to instantiate the class object.
HINSTANCE hDLL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer
char* key = new char [50];
key ="KEYVAULE";
char* strPlain = new char [50];
strPlain="password";
char* strResult = new char [50];
DWORD dwrd =NULL;
hDLL = LoadLibrary("Mydll.dll");
if (hDLL != NULL)
{
lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"LSGEncrypt");
if (lpfnDllFunc1 ==NULL) // Fails here? so DLL is freed up?
{
FreeLibrary(hDLL);
}
else
strResult = lpfnDllFunc1("killer" ,"strikes HERE");
}
Thanks
for thendral
|
|
|
|
|
Hi All,
Can anyone suggest me how to capture Desktop and record it?
Thanks in advance,
Poornima
|
|
|
|
|
what u want is to take a screen shot of the desktop and save it as bitmap.. just search on the code project..u will find many samples
nave
|
|
|
|
|
hi all,
I want to change the selected Full Row of the MSFlexGrid accordingly when mouse changes its cursor to next Row. I mean when Mouse is moved to the Second Row then the Current Selection must be Second Row.
In general the Selection of the Flex Grid is Static and does not depend on the Mouse Move. please help me out for this solution.
thanks,
uday.
uday kiran
uday kiran
|
|
|
|
|
Hi all,
I know I can use PlgBlt to rotate a defined rectangle, but i am not sure on how to use it properly, meaning i want to rotate a drawn rectanle (a rectangle which is drawn on a dialog using the method OnPaint) in 30 degrees.
The question is how to maintain the drawing, for example to to erase the old rectangle place, and how to draw the new rectangle place using the PlgBlt method...
code snippet could be nice
thanks in advanced
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
This example rotates text by 30 degrees - Replace the text rendering code with your drawing code. Will not work in 95/98/ME.
--------------------------------------
CPaintDC dc(this);
int OldMode = SetGraphicsMode(dc.m_hDC, GM_ADVANCED);
static const double pi = 4.0*atan(1.0);
static const double angle = 30.0*(pi/180.0);
static const XFORM xf = {cos(angle), sin(angle),
-sin(angle), cos(angle),
0, 0};
SetWorldTransform(dc.m_hDC, &xf);
CRect rcClient;
GetClientRect(&rcClient);
rcClient += CPoint(50, 50);
dc.DrawText(_T("Hello\nThere"), -1, &rcClient, 0);
SetGraphicsMode(dc.m_hDC, OldMode);
--------------------------------------
Steve
|
|
|
|
|
Thanks! it really helped....
A nicer way without using the PlgBlt method
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
Really a nice code.
Quite helpful.
Thanks again.
|
|
|
|
|
Hi Steve,
Aparently, this code only rotate the triangle in a 2 dimention way. suppose i use text inside the triangle, my request is to rotate the triangle (with the text inside) in 30 degrees, and this shift it so it would appear in 3 dimentions....
can u solve this one? should i now use PlgBit? if so , how? i need a code snippet.
thanks again
Yaron
Ask not what your application can do for you,
Ask what you can do for your application
|
|
|
|
|
I'm not sure what you mean - But I think SetWorldTransform can do everything that PlgBlt can. Can you explain what you mean better?
Steve
|
|
|
|