Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
if(Box->head == NULL)
{
Box ->head = Box -> tail = Box;
}
else
{
Box->tail -> next = Box;
Box -> tail = Box;
Box-> data = i;
}

All the nodes point to Box.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is NOT with my loop but with the way you created the linked list. All nodes in the list point to the same node. Each node has to be allocated each time it is added to the list. I know I have shown you how to do this a couple times before -- go back and study your other thread to see what you did wrong here.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It should work perfectly as long as n is less than the number of nodes in the linked list. If there are 5 resturants and you ask for the 6th node then my code will not work because there are not 6 nodes in the list.

I been tinkering the code AD helped me with .

doesn't work perfectly.
say the user types in 4 restaurants.

and it asks which restaurant to go.
1-3 doesn't work.
only 4 works. When I debug it.

I say if customer_number == cur->next->data
then cout<<"Hi What can I get you";

that only comes out when it's at the end of the list.
which is 4, since there's 4 restaurants for this example.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Are you doing this for a class assignment in school? Have you not studied for loops yet? If you have not, then you should do that before continuing.

>>count < n
That means that the loop will continue as long as the value of count is less than the value of n.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

After connecting to the server there is probably some sort of communication protocol strings the client has to pass to the server in order for the server to authenticate it. What strings that is will depend on the server. You will have to read the server's documentation to find out how to do it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thanks for the reply
i will be using the same
thanks a lot

His code isn't correct solution to your problem, but does give you a good start on it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know about gcc, but Microsoft compilers have an optimize pragma.. You might check of gcc has similar pragma. There is no similar pragma for _root that works on individual variables.

You might also try the volatile keyword.

Salem commented: volatile seems like a good match +30
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> if(strcmp(user,username)==0)

That is a case-sensitive comparison, so "John" is not the same as "john" due to capitalization. Depending on your compiler, use stricmp(), comparenocase(), or convert both strings to either upper or lower case before calling strcmp().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try this version

int cat(char **lawl, const char *catftw, const char *sub); 

int main()
{
    char adir[] = {"C:\\somedirectory\\"};
    char subdir[] = {"content\\"};
    char *dir; 
    int len;// pretty sure these char values are not initialized correctly
    cout << adir << endl << subdir << endl;
    len = cat(&dir,adir,subdir); // when properly initialized and passed no error in build but stops fails after getting lenths
    cout << len << "\n" << dir << "\n";
    return 0;
}


int cat(char **lawl, const char *catftw, const char *sub)
{
    int lens,lenm,tlen,x;
    char* ptr;
    for(x=0;catftw[x]!=0;x++)
        ;
    lenm = x;
    cout << lenm << endl;
    for(x=0;sub[x]!=0;x++)
        ;
    lens = x;
    cout << lens << endl;
    tlen = lenm + lens + 1;
    cout << tlen << endl;
    *lawl = new char[tlen];
    ptr = *lawl;
    while(*catftw)
	{
	    *ptr++ = *catftw++;
	}
    cout << *lawl << endl;
    while(*sub)
	{
	    *ptr++ = *sub++;
	}
    *ptr = '\0'; // null terminate the string
    cout << *lawl << endl;


return tlen;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the function does not need double star pointers (pointers to pointers). Therefore this line will not work right for(x=0;catftw[x]!=0;x++); >>lawl[x] = catftw[x]; //gives error when catftw properly initialized

As Gomer Pyle would have said: "Surprise, surprise surprise". lawl is a double star pointer and that line is treating it as a single star pointer.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Is there a way to define the < operator for Object somehow such that I can do this without having to modify Tools?

Of course there is. That's how std::sort function does it -- one of the arguments to std::sort is a user-defined function pointer, which sort() calls to determine sort order.

How to do it would depend on that Tools sort function and its arguments.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Sorry to say that edits are still sometimes broken.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Welcome to DaniWeb. Hope you find what you want. Please post that sort of info in Business Exchange forums. This one is for introductions only.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you mean so that the result looks like this?

0000000000
1654
</contact>
</desc>
</desc>
</desc>
</desc>
</name>
</name>
</phonebook>
</pop>
</pop>
</pop>
</pop>
</uri>
</uri>
</uri>
</uri>
<contact>
<desc>
<desc>
<desc>
<desc>
<name>
<name>
<phonebook>
<pop>
<pop>
<pop>
<pop>
<uri>
<uri>
<uri>
<uri>
Contact
Example
Laptop
Phone
a
l.jl
m
sip:contact@minisip.org
Press any key to continue . . .

#include <iostream>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>
using namespace std;
std::string strings[] = {
    "<phonebook>",
    "<name>",
    "Example",
    "</name>",
    "<contact>",
    "<name>",
    "Contact",
    "</name>",
    "<pop>",
    "<desc>",
    "Phone",
    "</desc>",
    "<uri>",
    "0000000000",
    "</uri>",
    "</pop>",
    "<pop>",
    "<desc>",
    "Laptop",
    "</desc>",
    "<uri>",
    "sip:contact@minisip.org",
    "</uri>",
    "</pop>",
    "<pop>",
    "<desc>",
    "a",
    "</desc>",
    "<uri>",
    "1654",
    "</uri>",
    "</pop>",
    "<pop>",
    "<desc>",
    "m",
    "</desc>",
    "<uri>",
    "l.jl",
    "</uri>",
    "</pop>",
    "</contact>",
    "</phonebook>", 
};
const int sz = sizeof(strings) / sizeof(strings[0]);
int main()
{
    vector<string> theList;
    for(int i = 0; i < sz; i++)
        theList.push_back(strings[i]);
    std::sort(theList.begin(), theList.end());
    for(int i = 0; i < sz; i++)
        cout << theList[i] << "\n";
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you would have to post all that code -- it shouldn't matter what *.cpp file contains main().

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Also please note that the variables mentioned in the errors are not used at all in a2main.cpp they were defined in console.c then redefined in screen.cpp,

You can't declare the same variables in two or more *.cpp files. Declare them in only one *.cpp file and use the extern keyword to declare them on other files. See example in my previous post.

Some compilers will discard unused variables during the optimization process, but apparently yours does not. In the case of your program I doubt any compiler would discard them because it doesn't know until link time whether the variables are actually used or not.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The most common reason for those duplicate declaration errors is declaring variables in header files without the extern keyword. extern tells the compiler that the object is actually declared in some other *.cpp or *.c file.

Here is an example of how you must declare variables in header files

// consol.h
#ifdef _cplusplus
extern "C" {
#endif
extern int _line;
extern int _cursor_pos;
extern int _col;
#ifdef _cplusplus
};
#endif

Now, in one and only one *.cpp file you have to declare them without the extern keyword

//console.c 
#ifdef _cplusplus
extern "C" {
#endif
int _line = 0;
int _cursor_pos = 0;
int _col = 0;
#ifdef _cplusplus
};
#endif
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hi,


I am using ubuntu linux.

GetProcessTimes(), GetThreadTimes(), GetSystemTimes() are windows API

So, install Windows Vista :) (I really have no clue, just wanted to post a smartass remark)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The only way I could make it work is like this, which is almost the same as you originally posted. And I think I would just leave it like that.

HWND MyTimerFunc(HWND hwndMainFrame)
{          // *************************************** START TIMER
   HDC  hDC;
   PAINTSTRUCT paintStruct;

   hDC = GetDC(hwndMainFrame);
    BeginPaint(hwndMainFrame, &paintStruct);
    SetTimer(NULL,0,1000,(TIMERPROC)TimerProc);
// ----- Remove below and the function fails --------------------------- TEST INFO
    //TextOut(hDC,1,20,"MyTimerFunc has been called.",28);
    EndPaint(hwndMainFrame, &paintStruct);
    ReleaseDC(hwndMainFrame, hDC);
// ----- Keep above and fuction works ---------------------------- TEST INFO

    return 0;
}          // ********************************* END TIMER
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I have compiled and run your program several times and I can't get SetTimer() to work either. I even started a whole new simple win32 api program that the compiler generated, and SetTimer() doesn't work there either. Finally tried google search for the problem -- other people have had the same problem but I didn't see any solutions!

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can use the WH_CALLWNDPROC hook if the process you want has a window. Other than that, I don't know if its even possible to do what you want.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you have been on MSN.com you may have already seen this video. Its a tutorial on how to cut down a tree :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If its the source code you want to protect, then the best you can do is put a copyright notice at the top of the software, then when you find someone who has stolen it you can sue him for copyright infringement. But lawyer fees might make that impractical.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>number = number / pow(10,(n-1.0));
Its still incorrect. 1 is subtracted from the return value of pow(), not from n. See the formula in my previous post number = number / (pow(10,n) -1 );

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Mr. Data had nearly human qualities when he left Star Trek. Quite a few gadgets invented on that show have now come to pass, so maybe it wasn't so far off with Mr. Data either.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

But I'm not talking about the pointer! You are just trying to be difficult. Change the function to this:

void foo(int arr[])
{
    arr[0]=0;//setting the first element of the array to 0
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>num = number / (10^n-1);

you have to use pow() function num number / pow(10,n)-1; The problem with that is if pow() returns 1 then the formula will get a divide by 0 error.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And the above pointer is passed by value. In effect it appears that the array has been passed 'by reference' but in reality, arrays are actually never passed to a functions.

True -- the pointer is passed by value, but the array (the memory location of the first element of the array) is by reference since it is not copied. When you declare an array in main() and pass it to foo(), any changes made to the values of the array in foo() are visible in main(). That is what I mean by pass by reference.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

or so it should have been ++ptr?
or ptr++.

if it's ptr+1, how isn't that the same as ptr = ptr -> next.
the ptr points to the node who's +1 from the current node right?
which isn't that the same as ptr = ptr -> next;

ptr->next is a pointer at some completly different memory location, which is probably not at (ptr+1). Lets say the address of ptr is 1000, so ptr+1 might be 1001. But ptr->next may have an address of 2000 because when you build a linked list each node is allocated with the new operator, or possibly malloc() function.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I am willing to pay $30/£20 for anyone to help me.
I don't work for less than $1,000,000/hour :) And payment must be in my paypal account before I'll start work.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

But you declared n in your post #5, above.

int n;
cout<<"Which list would you like to go to? \n";
cin>>n;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Seems to be solved now.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Hint: If the code in the timer proc TimerProc() takes more time to execute than the amount of time specified in the SetTimer() function call (1 second) then TimerProc() needs to kill the timer and restart it before leaving. Don't leave the timer running or the os will call TimerProc() again before it has finished processing the previous call. That can be disasterous.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

No, they are two different things. ptr++ does not increment the pointer to the next node, but mearly advances the pointer to the next memory location.

>>meaning does ++ move the ptr +1?
Yes, but that's not the same as ptr = ptr->next;

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>temp2 = 1+ RaceBonus / 100%;

what is that 100% ? The % in C++ (and C) is the mod operator, which is the remainder after division. So % doesn't make any sense there. Or is that supposed to be 100 percent?

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Is n supposed to be the node number, that is, when there are 10 nodes and n = 3, then it wants the 3d node?

node *ptr = cur_node;
int count = 0;
for( count = 0; count < n && ptr != NULL; count++)
{
    ptr = ptr->next;
}
// now ptr points to the nth node.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Just thought I'd let you know why misspelled words are not caught while you type today.

Nick Evan commented: http://www.extremefunnyhumor.com/pics/Google_Usage.jpg +17
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Humanity will become extinct with the next nuclear war. Nuclear war is much more likely to happen in our lifetimes than a nasty metor or solar flare.

An interesting film on the History Channel this morning speculating about why the dinosaurs became extincet some 65 million years ago. Current scientific thinking is that it was causes by a number of different actions -- volcanic ash, metors, and changing weather conditions. All those conditions could happen again, but I suspect nuclear war will wipe us out first.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

i'm just wondering, "where's the love?"

You must not be married -- if you had you would understand that married couples often squabble, but they still love each other. Besides, bitching is the whole purpose of this forum :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Except for the code tags problem I posted about in another thread everything seems to be working fine for me at the moment. I hope it stays that way :)

[edit]I spoke too soon. Things are not ok afterall, there are still database issues. But I'm pretty sure Dani is still working on this, so I'll wait. [/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

code tags with language are broken again. I just came across this thread that Narue added [code=cplusplus] ... [/code] and it didn't work. I removed the language and it worked ok.

[edit] I just went back to that thread and it doesn't work afterall. [/edit]

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You have to start at the beginning of the linked list and search for the node you want -- somethng llike this:

struct* node = head;
while(node->next)
{
   // check if this is the node you want
   //
   // now advance to the next node
   node = node->next;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 73 writes out the number of array elements. So line 86 has to read it.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>if you pass an array into a function by value the array
That's not possible -- arrays can only be passed by reference. Passing by value implies creating another copy of the array and passing the copy. The language does not support passing arrays by value.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't know about faster, but here is another way that only requires a single function. This function only writes to the screen, not to a file.

#include <string>
#include <ctime>
using namespace std;

void Passwords(int size)
{
    std::string pwd;
    pwd.resize(size);
    for(int i = 0; i < 128; i++)
    {
        for(int j = 0; j < size; j++)
        {
            char c;
            // do not allow duplicates in the password
            do
            {
                c = 35 + (rand() % 91);
            } while ( pwd.find(c) != string::npos);
            pwd[j] = c;

        }
        cout << pwd << "\n";
    }

}

int main()
{
    srand( (unsigned int)time(0) );
    Passwords(15);

}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>How to do this way???
You don't! Function implementations can not be put in header files for the reason you have already discovered -- duplicate definition errors.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Perhaps applicable, but really it just seemed like a very odd thing to contemplate wearing. ;)

Ohhh Yuuuk! You should be banned for even thinking that:icon_eek:

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The site has been very slow for everyone today -- I even got database error messages a couple times.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Where in that line does GPA appear? After reading the line from the file, move gpa to the beginning of the line to make sorting faster and easier. You could also copy gpa into a different array to make sorting much faster.

struct line
{
    char gpa[5];
    char ln[80];
};

when reading the file, build an array of the above structure, then sort the structures by gpa field.