|
As you use two different add functions for the two sortings, and each creates new nodes, you'll end up with two separate lists. If that was your intention you need only one next and one pre pointer for each list. If that was not your intention, then you need to create the new node outside the add function, and have the add function(s) just update the links appropriately.
|
|
|
|
|
well i create the node outside of the add functions and pass the node to these functions. in these add functions i update the links. but the main thing is which confuses me i use two add functions.(which updating the pointer of first name and second one is for last name). so if i wanna use only one list with having two different pointers(firstname pointer and lastname pointer) must i use only one add function_? or two functions. because adding one node for two different sortings in just one function will be very difficult_?. and sorry for inconvenience situtaion of my problem : ): here is the code again of my creating and calling add functions;
while ( !feof(myfile) ) {
NODE* pnew_stu;
if( !(pnew_stu = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
fscanf(myfile,"%s", &(pnew_stu->first_name) );
fscanf(myfile,"%s", &(pnew_stu->last_name) );
fscanf(myfile,"%s", &(pnew_stu->email_addr) );
fscanf(myfile,"%d", &(pnew_stu->phone_num) );
fscanf(myfile,"%s", &(pnew_stu->address) );
fscanf(myfile,"%s", &(pnew_stu->city) );
fscanf(myfile,"%d", &(pnew_stu->zipcode) );
add_fn_Node(list,pnew_stu);
add_ln_Node(list,pnew_stu);
}
and these are the adding functions
void add_fn_Node(LIST* list, NODE* pnew_stu) {
NODE* temp = list->fn_head;
if( !(temp = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
if( list->fn_head == NULL ) {
pnew_stu->fn_next = list->fn_head;
pnew_stu->fn_pre = list->fn_head;
list->fn_head = pnew_stu;
list->fn_count = 1;
return;
}
else {
temp = list->fn_head;
if ( (strcmp( pnew_stu->first_name, temp->first_name )) <= 0 ) {
pnew_stu->fn_next = temp;
pnew_stu->fn_pre = temp->fn_pre;
temp->fn_pre = pnew_stu;
list->fn_head = pnew_stu;
list->fn_count++;
return;
}
else {
while ( temp->fn_next != NULL ) {
if ( (strcmp( pnew_stu->first_name, temp->first_name ) <= 0 ) && (strcmp( pnew_stu->first_name, temp->fn_pre->first_name) > 0)) {
pnew_stu->fn_next = temp;
pnew_stu->fn_pre = temp->fn_pre;
temp->fn_pre->fn_next = pnew_stu;
temp->fn_pre = pnew_stu;
list->fn_count++;
return;
}
temp = temp->fn_next;
}
if ( temp->fn_next == NULL ) {
temp->fn_next = pnew_stu;
pnew_stu->fn_pre = temp;
pnew_stu->fn_next = NULL;
list->fn_tail = pnew_stu;
list->fn_count++;
return;
}
}
}
}
void add_ln_Node(LIST* list, NODE* pnew_stu) {
NODE* temp = list->ln_head;
if( !(temp = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
if( list->ln_head == NULL ) {
pnew_stu->ln_next = list->ln_head;
pnew_stu->ln_pre = list->ln_head;
list->ln_head = pnew_stu;
list->ln_count = 1;
return;
}
else {
temp = list->ln_head;
if ( (strcmp( pnew_stu->last_name, temp->last_name )) <= 0 ) {
pnew_stu->ln_next = temp;
pnew_stu->ln_pre = temp->ln_pre;
temp->ln_pre = pnew_stu;
list->ln_head = pnew_stu;
list->ln_count++;
return;
}
else {
while ( temp->ln_next != NULL ) {
if ( (strcmp( pnew_stu->last_name, temp->last_name ) <= 0 ) && (strcmp( pnew_stu->last_name, temp->ln_pre->last_name) > 0)) {
pnew_stu->ln_next = temp;
pnew_stu->ln_pre = temp->ln_pre;
temp->ln_pre->ln_next = pnew_stu;
temp->ln_pre = pnew_stu;
list->ln_count++;
return;
}
temp = temp->ln_next;
}
if ( temp->ln_next == NULL ) {
temp->ln_next = pnew_stu;
pnew_stu->ln_pre = temp;
pnew_stu->ln_next = NULL;
list->ln_tail = pnew_stu;
list->ln_count++;
return;
}
}
}
}
so am i not creating only one node and sending to these add functions_?. or am i creating two nodes again in functions and update them in the list_?
|
|
|
|
|
quartaela wrote:
NODE* temp = list->fn_head;
if( !(temp = (NODE*) malloc(sizeof(NODE))) ) {
printf("ERROR NOT ENOUGH MEMORY!!!\n");
exit(100);
}
if( list->ln_head == NULL ) {
...
}
else {
temp = list->ln_head;
What do you call malloc for here? I mistook this for the code that creates the node, but apparently it's just a mistake. Especially since temp gets overwritten later anyway.
So I was mistaken, there is only one list of nodes that you have. list->fn_head and list-> ln_head just point to different positions in your list.
|
|
|
|
|
so friend i know you will have a headache cause of my questions. . but i wanna ask a final question. why there aren't any differences between sending the node or its address like this;
add_fn_Node(list,&pnew_stu);
add_ln_Node(list,&pnew_stu);
and replacing every code
pnew_stu->fn_next
pnew_stu->fn_pre
with
(*pnew_stu)->fn_next
(*pnew_stu)->ln_next
and of course sorry that silly mistake of malloc
|
|
|
|
|
If you want to make these changes, you will also have to change the prototypes of the add_XY_Node() functions so they correctly reflect the type of the second parameter.
If you do that, the suggested changes should indeed work: Instead of passing the pointer you pass the address of the variable that stores the pointer, but inside the function you dereference that address again to get the original pointer. I see no reason to do that, unless you want to modify the pointer and pass that modification back to the caller.
|
|
|
|
|
thanks for your help stefan
|
|
|
|
|
At first glance, this seems to be overly complicated. I looked back through my archives and found some code I did for a doubly-linked list (that simply held an integer). The data structures were:
struct _node
{
int m_nNumber;
struct _node* m_pNext;
struct _node* m_pPrev;
};
struct _list
{
_list( void )
{
head = NULL;
tail = NULL;
}
struct _node* head;
struct _node* tail;
}; The function signatures were:
void addToFront( struct _list* pList, int nNumber );
void addToBack( struct _list* pList, int nNumber );
void addBefore( struct _list* pList, struct _node* pNode, int nNumber );
void addAfter( struct _list* pList, struct _node* pNode, int nNumber );
void insertAscending( struct _list* pList, int nNumber );
void insertDescending( struct _list* pList, int nNumber );
struct node* findNode( struct _list* pList, int nNumber ); To create a list of ascending integers, I would simply call insertAscending() , which looked like:
void insertAscending( struct _list* pList, int nNumber )
{
struct _node* pTemp = pList->head;
while (pTemp != NULL && nNumber > pTemp->m_nNumber)
pTemp = pTemp->m_pNext;
addBefore(pList, pTemp, nNumber);
}
void addBefore( struct _list* pList, struct _node* pNode, int nNumber )
{
struct _node* pTemp = new struct _node;
pTemp->m_nNumber = nNumber;
pTemp->m_pNext = pNode;
if (pNode->m_pPrev == NULL)
pList->head = pTemp;
else
pNode->m_pPrev->m_pNext = pTemp;
pTemp->m_pPrev = pNode->m_pPrev;
pNode->m_pPrev = pTemp;
} Breaking your code down into smaller, more manageable pieces will help you a lot.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Some people are making such thorough preparation for rainy days that they aren't enjoying today's sunshine." - William Feather
|
|
|
|
|
well mate i know my code is a little bit complicated but its reason is i am just in the beginning level of my project. i will make these operations at the end . anyway thanks for your suggestions
|
|
|
|
|
Hey Friends
I downloaded google chrome, clicked on download button, a eula was displayed and volla google chrome was downloaded and installed without any UAC prompt.
That's really nice , however when i create my own setup applications (with InoSetup) they display uac prompt.
If UAC prompt can be removed from setup, it would be great , is'nt it?
Any idea how google chrome setup is doing the magic?
Regards
|
|
|
|
|
For one thing. Chrome gets installed (on Win7) to C:\Users\Hans\AppData\Local\Google\Chrome. This is a user-accessible folder (unlike Program Files), so no UAC prompt.
Note: there might be other things that suppress the UAC interaction.
|
|
|
|
|
nops that does not seems correct.
the uac prompt is displayed before even the installation begins.
|
|
|
|
|
As I said, there might be other things involved, besides the installation folder.
Raj Aryan 1001 wrote: the uac prompt is displayed before even the installation begins. I have no idea what this means. You mean before you even click on the install package, you get a UAC prompt? That makes no sense.
Some other things: does your install package reference the registry? Have you checked the manifest settings?
|
|
|
|
|
forget about my installer, let's take any other installer, let's say internet explorer
when you download it will ask you whether to run it or save it?
google chrome does not asks to run it or save it, it just gets started automatically
now here the thing is that probably google chrome installer is running on my pc without any prompts whatsoever
installation page of google chrome
[^]
ie http://windows.microsoft.com/en-US/internet-explorer/products/ie/home[^]
|
|
|
|
|
Do you have a googleupdate app running on your PC?
|
|
|
|
|
yeah, is that the magic?
i have google toolbar installed
|
|
|
|
|
Raj Aryan 1001 wrote: yeah, is that the magic? Yep.
Sorry I misunderstood what you were asking.
|
|
|
|
|
that's brilliant, you cracked it
these hidden services can do anything
you are just brilliant, thanks
|
|
|
|
|
Raj Aryan 1001 wrote: it would be great , is'nt it?
No. If one user were able to install an app, remove an app, or alter an app in a way that affects all users of the system, it would not be great. It would be unsafe.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
yeah correct, but if application can get installed atleast for signed on user without uac prompts then it would be better i think (if it asks for admin password and user does not have admin password then user will not be able to install it and may be google chrome can be installed, will check)
|
|
|
|
|
Hi,
I am trying to make a brick game. I want to have a class for the players ball. The ball will split in 3 when a certain item is collected. The code compiles fine but when it runs it gives me the error "Object reference not set to an instance of an object." Also what's the best way of writing the code for 3 ball objects without having to duplicate code 3 times. Thanks.
#include "stdafx.h"
using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
public ref class Ball
{
public:
PictureBox^ gameBall;
int speed;
double xVel;
double yVel;
Ball()
{
}
void Add_to_form( Form ^ form )
{
speed = 5;
xVel = speed;
yVel = speed;
gameBall = gcnew PictureBox();
gameBall->BackColor = Color::LimeGreen;
gameBall->Size = Drawing::Size(20,20);
gameBall->Location = Drawing::Point(form->Width/2-35,form->Height/2-50);
form->Controls->Add(gameBall);
}
};
public ref class Form1 : public Form
{
public:
PictureBox^ paddlePlayer;
Timer^ gameTimer;
Ball ball1;
Form1()
{
this->Size = Drawing::Size(640,480);
this->BackColor= Color::SkyBlue;
this->MouseMove += gcnew System::Windows::Forms::MouseEventHandler(this, &Form1::pongMain_MouseMove);
gameTimer = gcnew Timer();
gameTimer->Interval = 20;
gameTimer->Start();
gameTimer->Tick += gcnew System::EventHandler(this, &Form1::gameTimer_Tick);
paddlePlayer = gcnew PictureBox();
paddlePlayer->BackColor = Color::LimeGreen;
paddlePlayer->Size = Drawing::Size(128,16);
paddlePlayer->Location = Drawing::Point(this->Width/2,this->Height-65);
this->Controls->Add(paddlePlayer);
this->Controls->Add(ball1.gameBall);
}
System::Void pongMain_MouseMove( Object^, System::Windows::Forms::MouseEventArgs^ e)
{
if(e->X < this->Width-paddlePlayer->Width - 18)
{
paddlePlayer->Location = Drawing::Point(e->X,paddlePlayer->Location.Y);
}
}
System::Void gameTimer_Tick(System::Object^ sender, System::EventArgs^ e)
{
ball1.gameBall->Location = Point(ball1.gameBall->Location.X + Convert::ToUInt32(ball1.xVel), ball1.gameBall->Location.Y + Convert::ToUInt32(ball1.yVel));
if(ball1.gameBall->Location.Y < 0)
{
ball1.gameBall->Location = Point(ball1.gameBall->Location.X, 0);
ball1.yVel = -ball1.yVel;
}
if(ball1.gameBall->Location.Y > this->Height - ball1.gameBall->Size.Height - 45)
{
ball1.gameBall->Location = Point(ball1.gameBall->Location.X, this->Height - ball1.gameBall->Size.Height - 45);
ball1.yVel = -ball1.yVel;
}
if(ball1.gameBall->Location.X > this->Width - ball1.gameBall->Size.Width-25)
{
ball1.gameBall->Location = Point(ball1.gameBall->Location.X,ball1.gameBall->Location.Y);
ball1.xVel = -ball1.xVel;
}
if(ball1.gameBall->Location.X <= 0)
{
ball1.gameBall->Location = Point(ball1.gameBall->Location.X,ball1.gameBall->Location.Y);
ball1.xVel = -ball1.xVel;
}
if(ball1.gameBall->Bounds.IntersectsWith(paddlePlayer->Bounds))
{
ball1.gameBall->Location = Point(ball1.gameBall->Location.X,ball1.gameBall->Location.Y);
ball1.yVel = -ball1.yVel;
}
}
};
[STAThread]
int main()
{
Application::Run(gcnew Form1());
}
|
|
|
|
|
Please repost your message in Managed c++/CLI forum.
"Every Little Smile can touch Somebody's Heart...
May we find Hundreds of Reasons to Smile Everyday... and
May WE be the Reason for someone else to smile always!" (ICAN)
|
|
|
|
|
Just create three instances of your Ball class. Instead of managing a single Ball instance, use a list of Balls, even when you only have one entry. Iterate over the list of balls each frame.
|
|
|
|
|
Thanks for the suggestion. It helped.
|
|
|
|
|
Hi,
I have created my own ownerdrawn menu, subclassed from CMenu, implementing the MeasureItem and DrawItem methods, which works flawlessly so far. However, I would like to change the visual appearance of the complete menu border, i.e. not the border of single menu items, but the whole menu border instead. Is there a good way to achieve this? Which method do I have to reimplement?
|
|
|
|
|
|