Murtan 317 Practically a Master Poster

The algorithm as posted only counts pixels that are green and only green. There is no provision for counting something that is 'almost' green.

The (0,255,0) represents the color...that's 0 parts red, 255 parts green, 0 parts blue.

The color (0,255,1) while visually VERY close, is not the 'pure' green and would not be counted.

Could this be your problem?

Murtan 317 Practically a Master Poster

I've never worked with Scheme, or Haskell so I can't readily debate their merits.

From what you posted that you know (VB and Assembly) I would recommend that you learn an object oriented language. The goal of working in the language is actually not-so-much to learn the language, even though that will be useful, but to learn to think objects as that skill will apply to any other OO language you might pursue. Python, Java, C++ and C# would all qualify as target languages in that regard.

@Rashakil

Have you ever used Scheme or Haskell in a commercial application, or have you used them primarily in an educational setting?

Murtan 317 Practically a Master Poster

You will have to declare an array of characters to input into, you can't input directly into the enum.

The % format for an array of characters is %s

Then you will have to compare what they typed against a list of strings you have to 'look up' the proper enum.

What do you want to do if the user enters a string that doesn't match any of the days?

(What day is it? Orange)

Murtan 317 Practically a Master Poster

Welllll, you COULD enter CTRL-A to get Monday, CTRL-B for Tuesday... (but I wouldn't recommend it).

I like some form of menu in this case, something like:

What day of the week is it? (1-Sunday, 2-Monday, 3-Tuesday...)

Then you could switch on the character entered and use it to set 'today' so the compare would work.

If you don't mind making it a little confusing for the user (bad form in my opinion, but to each his own) you could prompt for the actual enum value and scanf into an int.

What day of the week is it? (0-Sunday, 1-Monday, 2-Tuesday...)

@RenFromPenn

What do you want the user to type in at your prompt?

Could you 'type up' what you think the interaction should look like, then we could help you get the code to do what you want.

For the first case of mine above it would look like:

Please select the day of the week:
    1 - Sunday
    2 - Monday
    3 - Tuesday
    4 - Wednesday
    5 - Thurdsay
    6 - Friday
    7 - Saturday
What day of the week is it? 7

Hooray, it's the weekend!
Murtan 317 Practically a Master Poster

I thought that the vector code posted by Freaky_Chris was a great example of the parts of vector that you would be most interested in.

// declaring a vector
std::vector<std::string> genes;
// adding a string (genestring) to the vector
genes.push_back(genestring);
// accessing the second string 
//     (assumes there were at least 2 strings added)
std::cout << genes[1];
Murtan 317 Practically a Master Poster

This is the essential parts of the 'source' for the basic search form extracted from the web page you indicated:

<form action="/search.php#results" method="post">
<strong>Basic Search </strong>
<strong>First Name:</strong><br> <input name="fFIRSTNAME" type="text" size="10" maxlength="25" value="">
<strong>Last Name:</strong><br> <input name="fLASTNAME" type="text" size="10" maxlength="25" value="">
</form>

The <form> tells you that the form data is sent to the server via post, and the <input>'s give the field names 'fFIRSTNAME' and 'fLASTNAME'

You then 'encode' the form data and post it to the server.

There's a pretty good article on how to do that here:

http://www.voidspace.org.uk/python/articles/urllib2.shtml

Murtan 317 Practically a Master Poster

I like the vector solution to only read through the file once.

I'm presuming you would have 2 vectors, one for genes and one for cells.

Is is possible that genes or cells might occur more than once in the file?

If they do occur more than once, did you want to put all of the data from all of the ocurrances in the same vector?

As the file looks to be an XML format, can you rely on the tokens being the only thing on the line?

(i.e. will it always be:

<genes>
data
data
data
</genes>

or might you see

<genes>data</genes>

?

Murtan 317 Practically a Master Poster

I didn't have any problems compiling your code with VC++ Express.

There were 3 warnings about converting double to float for yourPos(.1, .2, .3) It seemed to run as expected as well.

Just a couple of other comments:

Member functions do not HAVE to use accessors, even if it is not 'this object'. This compiles and works too:

Point operator +(Point &p) const
        {
            return Point(itsX + p.itsX, itsY + p.itsY, itsZ + p.itsZ);
        }

You should make reference parameters const anytime you don't intend to modify them.

Here's a slightly modified and slightly expanded version of your code:

#include <iostream>
using namespace std;

class Point
{
    private:
        float itsX, itsY, itsZ;
    
    public:
        Point(float x = 0.0, float y = 0.0, float z = 0.0): itsX(x), itsY(y), itsZ(z)
        {}
        float getX() const { return itsX; }
        float getY() const { return itsY; }
        float getZ() const { return itsZ; }

        Point operator + (Point const & p) const
        {
            return Point(itsX + p.itsX, itsY + p.itsY, itsZ + p.itsZ);
        }

        Point & operator = (Point const & p)
        {
            itsX = p.itsX;
            itsY = p.itsX;    //yes, itsX used purposely throughout for testing
            itsZ = p.itsX;
            return *this;
        }
};

ostream & operator <<(ostream & stream, Point const & p)
{
    stream << p.getX() << " " << p.getY() << " " << p.getZ();
    return stream;
}

int main()
{
    Point myPos(1, 2, 3);
    cout << "myPos location:\n" << myPos << endl;
    Point yourPos(.1, .2, …
Murtan 317 Practically a Master Poster

After a little further searching, I don't see that any of the 'config' values from TFGame.uc (other than the one you are trying to add) are being used in TFMenuConsole anywhere.

Murtan 317 Practically a Master Poster

The if and else need to be 'inside' the case, and the if block and else block need their own set of braces { }. if (test) { // code } else { // more code }

case SMS_Construction:
			if(tfgame.ToggleWarhead == true)
			{
				SMNameArray[0] = "Shield (50/30)";
				SMIndexArray[0] = 1;
				SMNameArray[1] = "Protector (200/30)";
				SMIndexArray[1] = 2;
				SMNameArray[2] = "Portal (200/30)";
				SMIndexArray[2] = 3;
				SMNameArray[3] = "Armory (200/60)";
				SMIndexArray[3] = 4;
				SMNameArray[4] = "Generator (300/60)";
				SMIndexArray[4] = 5;
				SMNameArray[5] = "Outpost (600/90)";
				SMIndexArray[5] = 6;
				SMArraySize=6;
			}
			else
			{
				SMNameArray[0] = "Shield (50/30)";
				SMIndexArray[0] = 1;
				SMNameArray[1] = "Protector (200/30)";
				SMIndexArray[1] = 2;
				SMNameArray[2] = "Portal (200/30)";
				SMIndexArray[2] = 3;
				SMNameArray[3] = "Armory (200/60)";
				SMIndexArray[3] = 4;
				SMNameArray[4] = "Generator (300/60)";
				SMIndexArray[4] = 5;
				SMNameArray[5] = "Outpost (600/90)";
				SMIndexArray[5] = 6;
				SMNameArray[6] = "Warhead (3000/180)";
				SMIndexArray[6] = 7;
				SMArraySize=7;
			}

But this should work too and be a lot smaller:

case SMS_Construction:
			SMNameArray[0] = "Shield (50/30)";
			SMIndexArray[0] = 1;
			SMNameArray[1] = "Protector (200/30)";
			SMIndexArray[1] = 2;
			SMNameArray[2] = "Portal (200/30)";
			SMIndexArray[2] = 3;
			SMNameArray[3] = "Armory (200/60)";
			SMIndexArray[3] = 4;
			SMNameArray[4] = "Generator (300/60)";
			SMIndexArray[4] = 5;
			SMNameArray[5] = "Outpost (600/90)";
			SMIndexArray[5] = 6;
			SMArraySize=6;
			if(tfgame.ToggleWarhead == true)
			{
				SMNameArray[6] = "Warhead (3000/180)";
				SMIndexArray[6] = 7;
				SMArraySize=7;
			}

PS- please use c++ language code tags when posting c++ source
[code=c++] // your code here

[/code]

Murtan 317 Practically a Master Poster

If keeping the anonymous Atoms in a vector is what you have been doing, you were doing it right.

Objects from structs must be named for the compiler (according to the language's rules) at compile time, they cannot be defined at runtime.

But as I said before (and it is worth remembering) what the users see (or think they see) need not have any relationship to how the program stores and/or manipulates the data. If it is convenient, sure make the two similar, but when you run into a conflict, present the user with the 'correct' interface and massage the program to make it work. (Don't force the user to interact with the program in a certain way, just because that's how the data is stored/organized.)

Murtan 317 Practically a Master Poster

You never initialized aantal_getallen
which is the number of records to read/sort/print.

Murtan 317 Practically a Master Poster

And why are you posting in a thread last posted to in October 2007?

Murtan 317 Practically a Master Poster

This sounds a lot like another recent thread where the developer 'needed' to name the variables based on user input.

The name that you use inside the source need not have anything to do with the name the user sees. It would be your responsibility as the developer to map the elements of the array or vector or whatever other data structure you think would best fit your needs to the names the user is using.

Murtan 317 Practically a Master Poster

The reason it is main4() in my code is that this is the 4th version of the sort in the .py file main() was your version, main2() and main3() were versions of mine that did in another way. main4 is just a name, feel free to change it.

Python doesn't support a 'main'...the only reason your python file calls main is because you put main() at the bottom of the file without indenting it. So to run my code without losing yours, I wrote alternate versions of main (called main2, main3, main4) and called the one I was working on from where you called your main() .pop() always returns (and removes) the last thing on the list (unless you pass it an argument). If you were getting single letters, then the last thing on your list was single letters.

The following is the stream of input and output from an interactive python session: (started by just typing python)


This is what I saw when I typed what you posted:

>>> c=[0]
>>> print c
[0]
>>>

If c was a list, the c = [0] overwites the value.

Initialize a list and print the first item in the list:

>>> c =["Apple", "Banana", "Cherry"]
>>> print c
['Apple', 'Banana', 'Cherry']
>>> print c[0]
Apple

Iterating through the list to print it:

>>> for fruit in c:
...     print fruit
...
Apple
Banana
Cherry

Iterating through the list with indexes:

>>> …
Murtan 317 Practically a Master Poster

I'm kinda waiting on the OP (original poster) to see if they have been able to make the changes and get it to work so they can mark the thread solved or if there is more work to do to get it functional.

Murtan 317 Practically a Master Poster

As I understand it, Python couldn't care less how many spaces / tabs you use other than requiring that all lines within a block must have the same amount of whitespace.

Any statements you have which start a new block (see above in this thread) require that the new block has more whitespace than the statement which introduced it.

That being said, although it would be legal to indent your first block 1 space, your second 8 more, and your third 3 more (etc., randomizing at will) it would make your code much harder to read.

I'm firmly in the 4 spaces camp. I do like the look, but the first selection of 4 was because it was the editor default.

Murtan 317 Practically a Master Poster

Bladtman242

You're right, you can't go else ... else. Your second test however (if written right as else if (! enhp < 1) or as else if (enhp >= 1) ) is the true inverse of the first condition and the last else would never be executed.

The first else was fine as written. The second else was supposed to be the else for if (num == 1) In the full code, the user is prompted to select 1 for attack again, or 2 to flee.

Murtan 317 Practically a Master Poster

So ana and kata are moves in the fourth dimension of the matrix.

You mention giving a cell a reference to all 8 of its neighbors. That sounds like it might be the hardest part of building the data structure. (I'm presuming you mean a link to the nearest cell in that direction).

Just to clarify my understanding (seems like you have it all down), the four indices are used for the following directions: east(-)/west(+), north(+)/south(-), up(+)/down(-), ana(+)/kata(-).

So the 'neighbor' link in the east direction would be to the cell that has the last three index values the same and the next lower value in the first index?

Just curious, what if there are no more cells before the edge of the map? Are you going to use a 'null' pointer, a pointer to a signal value or pointer to an edge node?

For this thread, I think you've been more help to me than I was to you :)

Murtan 317 Practically a Master Poster

What is the '{' on line 1 before the if for?

Where is the '{' after the if on line 1?

Why do you have '{' '}' around the statement on line 3?

What is the '{' on line 5 for?

Line 14 appears to be the else for the if on line 1. The else needs to follow either, the single statement that follows the if, or the block of statements surrounded by '{' '}'. Neither is true so the compiler complains.

(The compiler has no clue which if statement line 14 might belong to, but it does know that it is not following a statement or block that was the 'true part' of an if.)

So, recommended changes:

remove the leading '{' on line 1 (unless it serves a purpose later)

put a '{' on line 2

remove the '{' '}' surrounding line 3

remove the '{' on line 5

add a '}' (preferably on its own line) between lines 13 and 14

Murtan 317 Practically a Master Poster

You didn't note any constraints other than "the array is mostly empty, and how can I make it smaller" so I wasn't concerned with any.

In the case of the dictionary, we would only store the data values that exist, the 'empty' spots would not exist. Testing for whether or not something exists in a dictionary is pretty straightforward but I'm not sure about your read/framerate.

So are you saying that for every frame, you might have to read 128,000 cells?

If so, what defines a 'manageable framerate'? (Is this really a 'I need to generate at least X frames a second' requirement?)

The method I proposed probably doesn't support a 'quick-fetch' of anything, let alone a hypercolumn.

To be honest, I'm not familar with the terms you're using. I supposing a hypermatrix is called that because it exceeds three dimensions?

What is a hypercolumn?

How is it defined in terms of the array dimensions?

(Which index values would remain constant? Which would change?
)

I attempted to google for your projection terms and didn't get any hits there either. Could you give a rough overview of how the projection is developed? (pseudo code is probably better than real code) for my purposes.

I'm trying to better understand what you are doing to see if I have (or can find) a 'better' answer.

Murtan 317 Practically a Master Poster

You could use a dictionary where the key was the composite index, something like key = "%d_%d_%d_%d" % (w,x,y,z) or key="W%dX%dY%dZ%d" % (w,x,y,z) . I think the dictionary would manage the collection fairly well.

Murtan 317 Practically a Master Poster

Ok...I will do this once, feel free to re-format afterwards, but here is your code. I put each brace '{' or '}' on its own line and then begged my editor to try to make it look better.

(I made no other changes, even though it needed them.)

#include <iostream>
#include <string>
using namespace std;
int main (void)
{
    int num, random_integer, hp= 100, enhp= 50;
    while (hp >=1 and enhp >=1)
    {
        srand((unsigned)time(0));
        for(int index=5; index<10; index++)
        {
            random_integer = (rand()%10)+1;
            hp = hp-random_integer;
            if (hp>=1) //remember, multiline if statements require brackets to function
            {
                cout<<"\nThe enemy does "<<random_integer<<" damage, leaving you with "<<hp<<" health.";
                cout<<"\n1)Attack!\n 2)I've had enough- run away!";
                cin>>num;
            }
            else
            {
                cout<<"You have died, better luck next time,";
                system("Pause");
                return 0;
            }
            {
                if(num ==1)
                {
                    srand((unsigned)time(0));
                    for(int index=10; index<20; index++)
                    {
                        random_integer = (rand()%10)+1;
                    }
                    enhp = enhp-random_integer;
                    {
                        if(enhp< 1)               //Victory condition. Breaks loop after enemy death
                        {
                            cout<<"The masked man falls to the ground, defeated.";
                            break;
                        }
                    }
                    cout<<"You have done "<<random_integer<<" damage." ;
                }
                else
                {
                    cout<<"You have fled"; break;
                }
            }
        }
    }
}
}
cout<<"Terrified, you run through the streets. Where is you father? If anybody'll know what to do, it'll be him.";
system("PAUSE");
return 0;
}

As noted by the previous poster, you're still calling srand() from multiple locations and from within a loop.

I would put one call to srand() between line 6 and line 7 and then get rid of the rest.

Murtan 317 Practically a Master Poster

somnathsarode if you are going to post code, especially in response to a thread, please use the appropriate code tags.

For this forum:
[code=c] /* your code goes here */

[/code]

Your response followed the original poster saying "Thanks ... did just what I wanted." Almost seems like the thread was answered doesn't it.

Murtan 317 Practically a Master Poster

Comments on the original code (that's all I have to look at):

You're really only supposed to call srand() once per run you don't have to call it everytime you want a random number.

In the original code, the 'I want to quit' option prints "You have fled" but it is still inside the for loop so it keeps fighting.

The outer while loop that we spent the time talking about is actually never tested. When the for loop terminates, the main() returns before the while gets a chance to be tested.

If your code has changed significantly, please re-post it.

Please use language specific code tags:
[code=c++] //your code here

[/code]

Murtan 317 Practically a Master Poster

Not to be picky, but #define NUMBERS is a pre-processor directive and doesn't get scope.

(But it should have been outside the function anyway.)

Aia commented: Correct +12
Murtan 317 Practically a Master Poster

Please, in the future, surround your posted code with code tags.
For C++ code they look like this:
[code=c++] // Your Code here

[/code]

My compiler complained about the #include "stdafx.h" because you didn't provide one. I removed the line and it compiled without errors.

There were two warnings on the use of strcpy() and strcat() as it is potentially unsafe. (There is no check to make sure you don't overflow the string you are copying or appending to.)

The first pointed me to an interesting construct, the Express constructor is copying to a global string?

// starting on line 50
char pstr[80];
size_t len;

// starting on line 85
class express{ 
public:
	express(char* ptr){
		strcpy(pstr,ptr);
		len=strlen(ptr);}
	void parse();
	float solve();
};

In fact, now that I look at it more, you have a list of global variables that seem to get used wherever they are 'needed'.

// starting on line 49
////////////////////////////////////////////////////////////////////////////////
char pstr[80];
size_t len;
Type* arr[20];
char ch;
char a[20];
char*pt;
size_t i=0;
int x=0;
int d;
float lastval;
char lastop;
float val1;
float df;
float v;
float v2;
char a2;
using namespace std;

From a design standpoint, you probably shouldn't be using global variables unless you can show that they need to be global.

I have for example no real issue with these:

const int LEN=80;
const int MAX=80;

But a comment as to what they are for would be nice. (Probably not essential on a one-off …

Murtan 317 Practically a Master Poster

The error I got was that ch was being used without being initialized

It pointed to line 5 in this code:

void express::parse(){
	int i=0,x=0;
	char ch;
	while(i<len){
		if(ch>='0'&&ch<='9'){

Where it is obvious that you declared ch on line 3 but have not assigned a value.

What did your error message say?

(Did you bother to read it?)

Murtan 317 Practically a Master Poster

I think maybe we have gotten 'off track'. The original problem was

Supposed to open a txt file. Assuming the txt file is formated properly. The file is a what I am assuming a list of names and ages. I created my own file...
kick me 989
bodybody 344
Santa Clause 0943
Bart Simpson 100
As Is 2856

Supposed to sort by the ages.

Most of the discussion (except for woooee's) has been about re-ordering the items on the line so you could use sort() (with the default parameters) to sort the list to meet your stated criteria.

What is the output supposed to be?

A list of the names in age order?

Bart Simpson
bodybody
Santa Clause
kick me
As Is

The same list with the ages included?

Bart Simpson 100
bodybody 344
Santa Clause 0943
kick me 989
As Is 2856

Would it be acceptable to list the ages first in the output?

100 Bart Simpson
344 bodybody
0943 Santa Clause
989 kick me
2856 As Is

For the outputs with ages, is it acceptable to output 943 in place of the 0943 we read for 'Santa Clause'?

We've read the file in with all lines at once and we've been working at reading one line at a time. Based on the stated goal, we will eventually need all of the data at once so we can order it. So one line a time is ok if …

Murtan 317 Practically a Master Poster

Did you mean to loop until both were dead, or until one was dead?

while (hp >=1 or enhp >=1)

Reads (in english) "While the player health is at least one or the enemy health is at least one, keep fighting"

I think you wanted to stop if either one died:

while (hp >=1 and enhp >=1)

Reads (in english) "While the player health is at least one AND the enemy health is at least one, keep fighting"

So this loop will stop when either one is dead.

(But the break would work too.)

Murtan 317 Practically a Master Poster

Ok this will be a bit of code, but bear with me. The concepts came from the tutorial link from the earlier post and some test code I wrote to make sure I understood how it works. (I've never used a map before today, but I've used similar objects from other languages.)

#include <map>
#include <string>
#include <utility>

void testcode()
{
    struct Person
    {
        int age;
    };

    map<string, Person> mapOfPerson;
    // or if you prefer you can use a typedef
    typedef map<string, Person> PersonMap;
    PersonMap People;

    // To add someone to the collection, you can do:
    People["Jim"].age = 19;

    // behind the scenes, when you referenced "Jim" the map found that he didn't exist
    // and then added him with a default value

    // This just adds Carl, but doesn't set his age
    People["Carl"];

    // You could also add someone "the hard way"
    Person sample;
    sample.age = 22;
    People["Bob"] = sample;

    // Once someone has been added, you can do things like:
    cout << "Bob is " << People["Bob"].age << endl;
    // Bob is 22

    // To determine who is in the list (or to find if someone exists) requires an iterator
    PersonMap::iterator finder;

    finder = People.find("Carl");
    // ok this part is a little more involved...but you can do things like:
    cout << finder->first << " is " << finder->second.age << endl;
    // Carl is 0

    // The previous example presumed that we would find what we searched for
    
    // We can find someone who doesn't exist,
    finder = …
NewtoC++ commented: Exactly what I was looking for +1
Murtan 317 Practically a Master Poster

To the best of my knowledge, it is not possilbe, and I can't imagine a scenario where it is really required.

I'm pretty sure that the map example (associative array) is really what he wants to do.

He wants to create an object and associate it with the name the user typed so that he can find the object again using the same name (possibly the user typed it again) later.

There is no reason that the code should have to have the variable name match. This is one of those places where the software needs to present an interface to the user that is not quite how the software implemented it. It is not all that uncommon of an occurance when working near the user inputs. It should not be a requirement that the user conform to how the program thinks about or deals with the data, it is up to the program to take the data from the user in the most convient way for them and massage it as necessary to get it to 'fit' the programs way of thinking.

As long as the software can accept the name the user enters to 'name' the object so that later it can be retrieved (and/or updated) through that name (whether remembered or re-entered), I believe that it has met the user request.

Newto, if you think that an implementation that makes it appear to the user as if you named the variable the …

Murtan 317 Practically a Master Poster

The return you have inside sorty will return from the function and the code that is 'supposed to read more data' will never get run.

What happened to names = infile.readlines() that read all the lines at once, then you could just iterate over every line in the list. (If you would rather read the file one line at a time I understand, but the 'read it all at once' works REALLY well unless the file is huge.)

As far as only getting one return value, that is a function of how your list works.

** PS - to make your code look like the following, please use [code=python] #your code here

[/code] around your code.

for index in names[:]:
    listofwords = index.rsplit(' ', 1)
    listofwords[-1] = listofwords[-1].strip()
    listofwords.insert(0, listofwords[-1])
    listofwords.pop()
    returnstring = ''
    for word in listofwords:
        returnstring += word + ' '
return returnstring.strip()

The last return does not get called until after the for loop completes going through all of the names. Each time through the for loop, the return string is cleared (on line 6 in my post) and then rebuilt.

So if there were three names in the list, the returnstring gets built for each name, but it is discarded before we do anything with it. The only result available when we call return is the last entry.

Comment regarding line 1:
Do you know what the syntax names[:] means?
That is a slice reference that creates …

Murtan 317 Practically a Master Poster

It's to the point now, where I wonder if you aren't intentionally trying to not understand. I don't believe that I've ever had this much trouble getting someone to 'get it', even when I was working in the computer lab helping first semester programmers all those years ago.

Based on the code you have posted, findUser() is now a 'search for user by name'. In that case, I told you to

Once you make that decision, you can either compare users[...].userID with userID or users[...].name with userName.

but you changed the compare to do something else entirely, you replaced the array index with the name (which makes no sense, no wonder the compiler complained).

As userID is the name of one of the members of the struct User, it makes a really bad name for a variable to index the array that contains instances of the User struct. Change the for loop and compare to the following:

for(int ii = 0; ii < noOfUsers; ii++)
{
    if  (users[ii].name == userName)
    {
        cout << "--------------------------------------------------" << endl;
        cout << "UserID: " << users[ii].userID << endl;
        // YOU put the rest of the print statments in
    }
}

As for the read routine that doesn't work, I refuse to help you any more with it until you post some code that compiles that shows you made an effort to solve the problem yourself.

And if you post your code again without using [code=c++] // your code goes here

Murtan 317 Practically a Master Poster

Does your lower case letter L look like a 1?

It does on my screen.

Murtan 317 Practically a Master Poster
char cmd[3]; // 3 byte array [0] [1] [2]
memcpy(cmd,packets,3); // cmd contains 'MSG' (confirmed)
if (cmd == "MSG") // not working
// try memcmp(cmd, "MSG", 3) == 0
{
       PA_OutputText(1, 1, lineNum, packets); //show on DS screen
}

// not working either
// if the last one was cmd[2] it might work
if ((cmd[0] == "M") && (cmd[1] == "S") && (cmd[3] == "G"))
{
       PA_OutputText(1, 1, lineNum, packets); //show on DS screen
}
Murtan 317 Practically a Master Poster

or, you at least need another index for the characters you put into packets. When you switch to a new x index, you need to reset the output index to 0.

void split(char *original)
{
  int x = 0;
  int i = 0;
  int jj = 0;

  while (original[i] != '\0')
  {
        if (original[i] == '@')
        {
           packets[x][jj] = '\0';
           x++;
           jj = 0;
        }
        else
        {
           packets[x][jj++] = original[i];
        }
        i++;
  }   
}

if the PA_WaitForVBL(); is necessary, what does it do?

Murtan 317 Practically a Master Poster

When you get to the actual sorting, you kinda need to compare numbers and not strings. When comparing strings, '1234' comes before '2', and that's just not right.

For the splitting of the name from the age, look at rsplit(' ', 1) that splits the string into an array of 2 strings on the last space in the line.

Then you can use int(agepart) to get the numeric value.

If you add the name and age to a list as tuples people.append((age,name)) (the double parens are on purpose) you can then use the default list sort() to order the list.

Murtan 317 Practically a Master Poster

You apparently know about using {code}{/code} (where you use square brackets instead of the braces). When posting C++ code, just make it look like {code=c++}{/code} (using square brackets). (I've seen people post what it's really supposed to look like, but I haven't figured out how to make it work yet.)

Now on to your current problem:

From my last reply on this topic:

The error on line 121 reads: no match for `string & == User *&' so the compiler thinks you're trying to compare a string and a pointer (or array) of users. Wait...that IS what you asked it to do.

You have repeated a previously mentioned 'bad form' and have declared (on line 119) an int userID that 'hides' the string userID from line 117.

The function prototype seems to indicate that you want to search for a user by ID, but you are trying to compare to the users's name? Which field are you supposed to be searching on?

That still applies to the current code. I'll try to point it out by adding comments.

// Here, we declare the "findUser" function with the following parameter:
//    the list of users "users" 
//    a "userID" 
//    the number of users "noOfUsers"
int findUser(User users[], string userID, int noOfUsers)                 
{
    // Now we declare a for loop to iterate over all of the users
    // we create the new variable "userID" to be the array index
    // NOTE: this is the SAME NAME as the …
Murtan 317 Practically a Master Poster

After looking at your data files, your read routines will need work too. The read routines seem to imply one piece of data per line, but the files are one record per line with ';' delimiters:

Samples from bookdata.txt:

Forsyth, Frederick      ;The fist of god               ;A;102391
Follett, Ken            ;The pillars of the earth      ;A;103795

Samples from userdata.txt

achillios           ; 27;old road                 ;10096
bains               ;  3;cirrus crescent          ;24397
Murtan 317 Practically a Master Poster

please, use code=c++ tags so it will number your lines

int findUser(User users[], string userID, int noOfUsers) //-------------------
{
for(int userID = 0; userID < noOfUsers; userID++)
{ 
if(users[userID].name == users) //Line:121-----------
{

The error on line 121 reads: no match for `string & == User *&' so the compiler thinks you're trying to compare a string and a pointer (or array) of users. Wait...that IS what you asked it to do.

You have repeated a previously mentioned 'bad form' and have declared (on line 119) an int userID that 'hides' the string userID from line 117.

The function prototype seems to indicate that you want to search for a user by ID, but you are trying to compare to the users's name? Which field are you supposed to be searching on?

The calls to open confuse me. I'm doing this in my program (it works with my original data file, I'll try it with yours too.):

fstream bookDataFile;
	Book books[MAX_BOOKS];
	bookDataFile.open("bookdata.txt");
	int noOfBooks = 0;
	while(!bookDataFile.eof() && noOfBooks < MAX_BOOKS) 
	{ 
		getline(bookDataFile, books[noOfBooks].authorSurname);
		getline(bookDataFile, books[noOfBooks].authorFirstname);
		getline(bookDataFile, books[noOfBooks].title);
		getline(bookDataFile, books[noOfBooks].category);
		getline(bookDataFile, books[noOfBooks].bookID);
		if (! bookDataFile.eof())
			noOfBooks++;
	}
	bookDataFile.close();

You might see if bookDataFile.open("bookdata.txt", ios_base::in); works any better for you, your library seems to want a second argument. Alternatively, you could try declaring the streams as ifstreams ifstream bookDataFile; maybe that would make it work without the second argument.

Murtan 317 Practically a Master Poster

Books and author may have been defined on line 90, but that was inside another function. Line 121 is in a different function, so the variables are undefined. (This concept is called the scope of a variable.)

But could you explain why in the findUser function you're looking at the books anyway?

Murtan 317 Practically a Master Poster

I'm not sure what your problem is. The code:

int findBookAuthor(Book books[], string author, int noOfBooks)
{
	for(int bookNo = 0; bookNo < noOfBooks; bookNo++)
	{ 
		if(books[bookNo].authorSurname == author)
		{

Compiles and runs on my system.

I call it from the main code like:

case 2:
			cout << "Enter Author Name: ";
			cin >> author;
			bookID = findBookAuthor(books, author, noOfBooks);
			break;

And it will find and display the book. (I think it would display multiple books, but I only have 2 books in my file.)

Murtan 317 Practically a Master Poster

tutti,

We haven't been working on this thread for over 2 weeks...if you want to get help with your program, start a new thread and show us your work.

Murtan 317 Practically a Master Poster

you're not supposed to take part of the discussion out of the thread...now if someone were to search and find this thread, they can't see what you learned.

For random number generation, I like the python random module:

import random
op1 = random.randint(1,10)
op2 = random.randint(1,10)
sum = op1 + op2
print op1,'+',op2,'=',sum
Murtan 317 Practically a Master Poster

That one change fixed almost all the errors in my test project and the remaining error was so blatant I suspect you can solve it.

(If not, post your new code with your new errors and we can look at it again.)

Murtan 317 Practically a Master Poster

most of your compile errors are in the library headers?

Are you missing a switch (compiler option)?

(I'm trying to compile it in Visual C++ Express and I'm getting an entirely different set of errors.)

Murtan 317 Practically a Master Poster

The headers (include files) define the names so the compiler knows what things can be done with the name.

The compiler then goes through and genereates symbol references in the object file. For example cout << " deneme " is a call to a method something like ostream & ostream::operator << (char const *) which for an ostream puts the string into the output stream. At the object file level, it knows that it needs to resolve the method.

The linker collects the object files with all of their undefined symbols and attempts to resolve them through the list of librarys (both default and specified).

Murtan 317 Practically a Master Poster

Microsoft C / C++ support an extension that a header file could use to add a default library to search. It is a preprocessor pragma that puts a comment record in the object files: #pragma comment( lib, "emapi" ) (where 'emapi' could be any library name). The end effect when this is encountered by the linker is to add that library to list of default libraries to search for.

It is however uncommon to see them used as if you have different library names based on any compile options, you would have to also detect the compile options to make sure you specify the correct library name.

Murtan 317 Practically a Master Poster

That's not a library reference, that's an include file reference.

The compiler (ok, maybe the preprocessor) will search for a file of the specified name through each of the directories in the include path. It will use the first file it finds. The contents of the file it finds are 'included' as if they were actually typed in that location.