Murtan 317 Practically a Master Poster

I googled the function name and came up with this description:

The function cvCalcOpticalFlowBM calculates optical flow for overlapped blocks blockSize.width×blockSize.height pixels each, thus the velocity fields are smaller than the original images. For every block in imgA the functions tries to find a similar block in imgB in some neighborhood of the original block or shifted by (velx(x0,y0),vely(x0,y0)) block as has been calculated by previous function call (if usePrevious=1)

So it would seem that the function is trying to measure motion between two pictures. It looks for matching blocks in each picture and returns the speed at which the block(s) were moving.

It is returning how far in x and how far in y the block moved. If you need a vector for the motion, you will probably have to calculate it from the velX and velY.

Murtan 317 Practically a Master Poster

at.exe is in my system32 directory, so I suspect you could use CreateProcess on it.

Murtan 317 Practically a Master Poster

The wikipedia article talks about the two fonts because the cipher is designed to be used as steganography (hiding in plain sight).

First you take your coded message
I'm lazy so my message is "apple".

Then you baconize it:

AAAAA ABBBB ABBBB ABABB AABAA

Then you use the a's and b's to apply the two fonts.

For this medium I'll use uppercase to represent a B and lower case for an A (though this oversimplifies it)

my 'plain' message:
python is a language that makes programming fun.

now aligned with the bacon:

python is a language that makes programming fun.
AAAAAA BB B BABBBBAB ABBA ABAA

(It would be better if my plain message was the same length as the baconized code.)

and uppercasing the B's (though the 'true' example would use a different font.

python IS A LaNGUAgE tHAt mAkes programming fun.

The coding is in which font is used for each letter. You decode the message by decoding A and B for the different fonts and then un-baconize to get the coded message.

Murtan 317 Practically a Master Poster

I agree with grumpier, if you have to use the system() call, you're stuck with the "black window". But unless you're calling batch files, you can probably avoid the system() call.

Murtan 317 Practically a Master Poster

If you have an assignment you want help with, describe the goal, any requirements and post YOUR code to show what you've done.

Then we'll help you get from where you are to where its done.

PS- please surround your c++ code with code tags:
[code=c++] // your code here

[/code]

Murtan 317 Practically a Master Poster

That sure looks like an assignment to me. We generally don't do your assignements for you. If you want help with it, you give it a start and then ask questions about the problems you're having. (And what's with the poll at the top of your plea for help?)

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

ok, I did the default constructor and called resize(). The assert is gone and the program runs.

I also did a little more playing, I added a third player 'Bob' who is also a CPU (not that it really matters right now).

Here's the output from my last run:

### HAND 1 ###
CPU's hand: Nine of Hearts, Ten of Spades, Jack of Hearts, Queen of Spades, King of Spades
Bob's hand: Ace of Spades, Eight of Spades, Jack of Diamonds, Jack of Spades, Queen of Hearts
Ludovico's hand: Eight of Hearts, Nine of Diamonds, Ten of Clubs, Jack of Clubs, Queen of Clubs

CPU has Straight, King high
Bob has One Pair, Jack
Ludovico has Straight, Queen high

### HAND 2 ###
Bob's hand: Ace of Hearts, Eight of Diamonds, Ten of Diamonds, Jack of Clubs, King of Clubs
Ludovico's hand: Eight of Clubs, Nine of Spades, Queen of Diamonds, Queen of Spades, King of Diamonds
CPU's hand: Ace of Diamonds, Ace of Clubs, Nine of Diamonds, Ten of Hearts, King of Hearts

Bob has High Card, Ace
Ludovico has One Pair, Queen
CPU has One Pair, Ace

### HAND 3 ###
Ludovico's hand: Ace of Hearts, Ace of Diamonds, Eight of Diamonds, Jack of Diamonds, Queen of Diamonds
CPU's hand: Nine of Diamonds, Ten of Spades, Jack of Spades, King of Diamonds, King of Clubs
Bob's hand: Eight of Hearts, Ten of Diamonds, Jack of Hearts, Jack of Clubs, King of Hearts

Ludovico has One …
mrboolf commented: Wow, what a post! Thank you! Now that Christmas is gone I think I'm going to partially rewrite this project following some of your advices before going on. Thanks again for your time :-) +2
Murtan 317 Practically a Master Poster

I'm seeing an assertion (for array index out of bounds) on the last line posted below:

void pokerGame::showdown() {
    m_points.clear();
    m_points.reserve(m_numPlayers);
    for(int i = 0; i < m_numPlayers; ++i) {
        if(m_arePlaying[(i+m_turn)%m_numPlayers]) {
            m_points[(i+m_turn)%m_numPlayers] = pokerPoint(m_players[(i+m_turn)%m_numPlayers].getHand(), m_minInDeck);

The clear() gets rid of all of the elements in the vector.
You call reserve() which makes sure the array can hold that many but doesn't fill it.
You could call resize() to actually change the size of the vector, but it appears that it would require pokerPoint to have a default constructor and it doesn't have one.

What do you think about giving pokerPoint a default constructor that sets it to a non-hand (or really low hand if a non-hand isn't possible). Then instead of calling clear() and reserve(), leave the pokerPoint instances in but call a new method pokerPoint::update(hand h, value minInDeck) passing in the players hand. This new method would update the pokerPoint based on the new hand. (You could keep re-constructing them to get the points, but is there a value added to create/destroy/re-create?)

I may try to do something like that myself just to get it running again.

Murtan 317 Practically a Master Poster

Please make the following changes (if you can) so I don't have to re-make them the next time I re-import your code:

Add #include <time.h> to deck.cpp and game.cpp

(You know you're only supposed to call srand() once per program run, right?)

Add #include <algorithm> to game.cpp and hand.cpp

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

The printf("\r") works really well to have the console screen overwrite the 'current' line. It will however just be another character in the output if cout is redirected to a file.

I used to use that feature to show progress for an old command line compiler, it would output the current source line number and then use '\r' to 'go back' and overwrite it with the next line number.

When the line numbers weren't important, I've also used it to make a 'spinner' using the character - \ | / in rotation. (If used sequentially, it looks like the line is 'spinning' in place.) So the user could see that the program was really still doing something.

And its been a while, but I vaguely remember that there were O/S dependent ways to detect if cout was to the console or a file. (It's always better if you don't care, but features like the "I'm still alive spinner" make no sense in the file.)

Murtan 317 Practically a Master Poster

The code looks like it ought to work.

Could you try something for me? (Look for compiler errors or warning around this area, it might be a clue).

(Note: if your first code tag says code=c++ you get line numbers and syntax highlighting)

void outputQueue(queue<pcb*> readyQueue) {
    queue <pcb*> temp (readyQueue);
    for (int i = 0; i < readyQueue.size(); i++) {
        pcb * ptf = temp.front();
        cout << "temp.front's number: " << ptf->pid << endl;
        cout << "temp.front's name: " << ptf->name << endl;
        showData(ptf);
        temp.pop();
    }
}

I added line 4 to make sure it explicitly has the type I want. Then I use it for the outputs on lines 5 and 6 and pass it to the function on line 7.

Please try that and let me know what if anything happens.

According to the reference I found, temp.front() actually returns a const TYPE & where TYPE is pcb * so we're getting something like a const pcb * & and I'm wondering if something related to the const is trying to 'help' you.

Murtan 317 Practically a Master Poster

The code at the end of your last post missed the point of the '*' outputs. I'm pretty sure it is supposed to be a histogram of the number of times that a particular value was entered.

So if the input was: 10, 9, 5, 9, 2, 9

The output would be something like:

10) * 
09) * * * 
08) 
07) 
06) 
05) * 
04) 
03) 
02) * 
01)

So the program not only needs to collect the data, but count how many times each number was seen to develop the histogram.

Murtan 317 Practically a Master Poster

I pulled the download from the link you gave. In my quick scan of the files, it doesn't appear to have a tutorial, but it did have some sample code.

However at the end of the thread there were requests about making it compatible with XNA 2.0 and the response was that Microsoft had provided a solution so he wasn't going to maintain his any more. The link he provided went here. There is some sample code here too, but I didn't download it and I didn't see a tutorial.

It seems both methods involve deriving custom user controls from a 'special' control that has some support for XNA.

Generally to be successful at getting help here, you post some code, explain what it currently does and how that differs from what you really wanted it to do.

Then people will usually give you pointers on things to try to get the result you want. Very rarely does anyone provide a canned solution unless you're really really close.

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

People write introductions and tutorials so they don't have to answer the same question every time someone new gets it.

Please try to use the resources that exist before trying to have someone re-invent the wheel. If you look at something and you don't "get it" feel free to post what you have and ask specific questions, you get much better replys

Murtan 317 Practically a Master Poster

malloc is the right solution, but you can treat a pointer to allocated memory like an array of the same type. As I said, the expressions are interchangeable, I just prefer the second.

isn't tmp the number of bytes between sections?

the code never updated clrcnt so if it was zero, all data is stored in the first entry in the table. If it was non-zero, all the data is stored at that index.

This would work

int clrcnt = 0;
for (int i=0; i<(3*tmp); i++)
{ 
    if (tmp2==3) 
    {
        tmp2=0; 
        clrcnt++;
    }
    i1=fgetc( ipFile );
    if (tmp2==0) {
        *(glblclrtab + clrcnt) = (char)i1;
    } 
    else if (tmp2==1) {
        *(glblclrtab + tmp +clrcnt) = (char)i1;
    } 
    else if (tmp2==2) {
        *(glblclrtab + 2*tmp + clrcnt)= (char)i1;
    }
    tmp2++;
}

This is cleaner:

int clrcnt = 0;
for (int i=0; i<tmp; i++)
{ 
    i1=fgetc( ipFile );
    *(glblclrtab + clrcnt) = (char)i1;
    i1=fgetc( ipFile );
    *(glblclrtab + tmp +clrcnt) = (char)i1;
    i1=fgetc( ipFile );
    *(glblclrtab + 2*tmp + clrcnt)= (char)i1;
    clrcnt++;
}

now that i and clrcnt always have the same value:

for (int clrcnt=0; clrcnt<tmp; clrcnt++)
{ 
    i1=fgetc( ipFile );
    *(glblclrtab + clrcnt) = (char)i1;
    i1=fgetc( ipFile );
    *(glblclrtab + tmp +clrcnt) = (char)i1;
    i1=fgetc( ipFile );
    *(glblclrtab + 2*tmp + clrcnt)= (char)i1;
}
Murtan 317 Practically a Master Poster

I took the zip file and made a MS project around it.

I had to add #include <algorithm> to hand.cpp but other than that it compiled.

I then uncommented your troublesome line:

void pokerGame::showdown() {
    for(unsigned int i = 0; i < m_players.size(); ++i) {
        if(m_players[i].getHand().getSize()!=0) {
            std::cout << m_players[i].getName() << "'s hand: ";
            std::cout << m_players[i].getHand() << std::endl;
        }
    }
    return;
}
void pokerGame::showdown() {
    for(unsigned int i = 0; i < m_players.size(); ++i) {
        if(m_players[i].getHand().getSize()!=0) {
            std::cout << m_players[i].getName() << "'s hand: ";
            std::cout << m_players[i].getHand() << std::endl;
        }
    }
    return;
}

It runs ok, but the output is strange:

dealing to Ludovico
dealing to Cpu
dealing to Ludovico
dealing to Cpu
dealing to Ludovico
dealing to Cpu
dealing to Ludovico
dealing to Cpu
dealing to Ludovico
dealing to Cpu
Ludovico's hand: Ace of Nine, Two of Spades, Four of Five, Three of Six, Four of
 Six
Cpu's hand: Ace of Ace, Ace of Five, Two of Four, Ace of Six, Two of Seven

I think the problem is here:

void deck::build(int numPlayers) {
    m_discarded.clear();
    m_dealt.clear();
    m_deck.clear();
    if(numPlayers == 0) {
        for(int i = 1; i <= 4; ++i) {
            for(int j = 1; j <= 13; ++j) {
                // -- a card expects value , suit which is what we say we're passing
                // -- but j is 1-13 and i is 1-4
                m_deck.push_back(card((value) i, (suit) j));
            }
        }
        return;
    }
    for(int i = 1; i <= 4; ++i) {
        m_deck.push_back(card((value) 1, …
mrboolf commented: Great, you saved me from a big headache! Thanks +2
Murtan 317 Practically a Master Poster

I think it was pretty obvious that I saw and read your code.

I don't believe in solving the problem for you, I believe in giving you the tools to help yourself.

One of the really cool things about python is that it is pretty fast to try most things, and if you're not sure how something works, you can play with it interactively to see how it really works and functions.

If you're not sure where to put stuff, make an educated guess as to where it would go and then try it. If it didn't work, but gave you another idea try that...if you've been struggling for a bit and have run out of ideas, post what you have (or the part you're having trouble with) and I'll try to help some more.

For example the part about saving the results...you probably have to declare the empty list before you start playing and add something to the list every time you determine a winner (or a tie). Then at the very end of the program, you go back through the list to recap the results.

Murtan 317 Practically a Master Poster

If I read the code right, the intent is to split up color table values?

bytes in the file come as r,g,b,r,g,b...

You want the array to contain r,r,r...g,g,g...b,b,b...

Is that close?

if so, what do you think of:

char *glblclrtab;
glblclrtab= malloc(3*tmp); 

for (int i=0; i < tmp; i++)
{ 
    glblclrtab[i] = fgetc( ipFile);
    glblclrtab[i + tmp] = fgetc( ipFile);
    glblclrtab[i + 2 * tmp] = fgetc( ipFile);
}

for (int i = 0; i < tmp; i++)
{ 
    printf("%d::%d, %d, %d \n",
        i,glblclrtab[i], glblclrtab[tmp + i],glblclrtab[2*tmp+i]);
}

free (glblclrtab);  // program nolonger aborts

note that *(glblclrtab + i) is functionally equivalent to glblclrtab[i] but the second is way easier to read.


What was the variable clrcnt in your code?

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

His posted code was not intended as a solution, but as a guide into you finding your own solution.

The function "GetGoodAnswer" is full of comments telling you what it should be doing, but it doesn't actually do any of what you see.

And no, that print isn't going to work yet. Once you have your list of 20 numbers from 1 to 10, you have to count how many of each number you got.

Then you can start working on outputting one star for each one you found. (That part might have some of what you had in your print statement.)

Murtan 317 Practically a Master Poster

Ok this first comment is pretty minor, but I'll mention it anyway. The code for setup randomly selects the players card and the dealers card, then removes both cards from the deck. It does this twice to for the initial two cards. There is a chance (pretty small, but it is still there) that the dealer and the player could select the same random index from the deck. You would then add the same card to both hands and then remove the same index twice. The second call would remove a card that wasn't in either hand. You might consider a 'deal a card' function that would generate a random index into the deck, save the card it found, remove the card from the deck and then return the 'saved' card. Alternatively, you could pass the hand that it should append the card to if you like that better.

More importantly, the logic inside the loop isn't quite right. The blackjack game normally allows the player to draw more than once if they want to, so you can't compare the hands until the player 'stays'.

Also, the dealer doesn't get to take any cards until the player 'stays', but always has that option when the player does 'stay'.

You will need to maintain a list of the hand results if you want to be able to 'recap' the hands when they quit. It could be as simple as appending a tuple with the player score and then …

Murtan 317 Practically a Master Poster

Give me a little more help so I can help you.

What would an example input string look like?

What output(s) would the code need to produce?

Murtan 317 Practically a Master Poster

The problem with using "A-" as a variable name is that it is illegal.

You can create a variable A_minus without any problem, but you don't want the user to be inputting your variable names anyway.

You will want to take their input as a string "A-" and use that to find the appropriate point multiplier.

This seems custom aligned for a dictionary.

gradepoints = {}
gradepoints["A"] = 4.00
gradepoints["A-"] = 3.70
# put the rest of the relationships here
# There is an easier way to initialize dictionaries, 
# feel free to find it and use it

Then you can use the user input to 'index' into the dictionary to get the point multiplier.

Try to use the idea in more of your own code and post any problems you find.

sneekula commented: Nice approach to help +6
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

This didn't make any sense?

self.rtc.BeginTextColour((255, 0, 0))
        self.rtc.WriteText("colour, like this red bit.")
        self.rtc.EndTextColour()

It looks like you have to 'build' the contents of the Rich Text Control as you go. When you get to text you want in another (non-default) color, you call BeginTextColour with a tuple that contains the desired RGB (Red, Green, Blue) components. In this case (255,0,0) says use as much red as you can, but no green and no blue. This should end up a 'bright red' color. Once you have output all of the text you want in the selected color, you call EndTextColour() to return to the previous (or default) color. (I'm not sure whether or not wxpython maintains a stack of colors to return to.)

Murtan 317 Practically a Master Poster

Please, when posting python code, use code=python tags

As I said in my previous messages, you needed to indent more lines to make them part of the loop.

house= ["computer", "laptop", "tv", "nintendo DS", "table", "Empty"]
print "items in my house are:"
print house
    
while house[5] == "Empty":
    print "Pick an item to fill in the empty space: \n1 - Lamp\n2 - bed\n3 - NDS\n\n"

    choice=raw_input("Type a number and press enter: ")
    print


    if choice =="1":
        house[5] = "lamp"
        print "Items in my house are now:"
        print house

    elif choice =="2":
        house[5] = "bed"
        print "Items in my house are now:"
        print house

    elif choice =="3":
        house[5] = "NDS"
        print "Items in my house are now: "
        print house

    else:
        print "\nYou need to pick a number from 1-3"

In python, the indenting is CRITICAL to the program structure, so much so that having two items indented at different levels is actually a compiler error: (** This code will NOT compile **)

sum = 0
for x in range(5):
    sum += x
        print x, "new sum", sum

It is actually one of the several features of python that I love. Either learn to love it, learn to live with it, or move on to another language.

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

Python does string or number pretty well. If you need variables that are a specific size in bytes, look at ctypes

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

The first point was a link to an article that describes why the concept of 'security through obscurity' was false. (The concept that just because you aren't telling anyone about how you do something that it is therefore secure.)

The second half about the 'big enough target' refers to the fact that if there is a big enough reward, someone will put in the effort required to break any security.

Murtan 317 Practically a Master Poster

yes

Murtan 317 Practically a Master Poster

Both of your examples will do the same thing as the sizeof(char) is 1.

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

In all of the code here, I don't really see the point for the threading. Unless you've simplified the code to demonstrate your question, reading from a file doesn't usually take very long (unless its really big) and in any case, there is nothing else going on so we end up waiting for it anyway.

Now if the point was to read from a website instead of a file, that's an operation that can take some time, but unless we have something else to do, there is still no point to the threading.

If you were trying to collect data from multiple websites at once, then it makes more sense to have the threading. You could start all (or several) of the requests at once and wait for them all to be complete before doing something with the data. (The requests would all run at the same time instead of having to wait for the first site to respond before the second request was sent.)

If your intent is something like the last case, then either of the two scenarios that Gribouillis presented would be good.

Another option would be to have the threaded object collect the data and then 'deliver' the data through a callback. If you were to pass a function to the threaded object before you call start, the threaded object could collect the data and then call the function passing the data. The callback could add it to a list or do …

Murtan 317 Practically a Master Poster

I don't think I understand your request.

Are you saying that your program creates a folder and then puts some files in it?

Then later, your program creates another folder and you want to move the files from the first directory to the second?

Murtan 317 Practically a Master Poster

It seems to work right in my sample code. If you still can't make it work, post your code (and your output if possible) and we can look it over again.

Murtan 317 Practically a Master Poster

I specifically did NOT post fully working code...it is YOUR assignment.

You needed to indent more of the code that followed.

Specifically, the input and the tests.

All of this should have been in the loop too:

choice=raw_input("Type a number and press enter: ")
print


if choice =="1":
    house[5] = "lamp"
    print "Items in my house are now:"
    print house

elif choice =="2":
    house[5] = "bed"
    print "Items in my house are now:"
    print house

elif choice =="3":
    house[5] = "NDS"
    print "Items in my house are now: "
    print house

else:
    print "\nYou need to pick a number from 1-3"