pseudorandom21 166 Practically a Posting Shark

Yes the variables you initialize in the body of the for-loop are local to the loop body's enclosing scope. I think that's written somewhere or something.

In older implementations of C++ that was actually an option for Microsoft's compiler, probably even Version 6.0 of it. Heck there may still be an option to make the variables persist.

pseudorandom21 166 Practically a Posting Shark

Search for record by student ID:

#include <iostream>
#include <string>
#include <fstream>
#include <sstream>
using namespace std;

int main()
{
   ifstream inFile;
   string result = "";
   string id = "10364";
   string line;
   inFile.open("records.txt",ios::binary);
   while( getline(inFile,line) )
   {
      stringstream ss(line);
      if( ss >> result )
      {
         if(result == id)
         {
            //parse the rest of the record.
         }
      }
   }
   
}

Happy Holidays, and beware of potential bugs, this isn't your entire assignment, just a sample of something that will hopefully work.

http://fredosaurus.com/notes-cpp/strings/stringstream-example.html
http://www.cplusplus.com/reference/iostream/stringstream/stringstream/


As for your existing code, every time I see while (!inF.eof()) it means that you may not be aware of it reading one past the end of the file, basically it reads the EOF stuff because .eof() only returns true after you hit the end of the line.

I've always followed this example and it has served me well:

string word;
string number;
ifstream inFile("somestuff.txt",ios::binary);
while( inFile >> word >> number )
{
   cout << word << " " << number << endl;
}
if(inFile.bad())//if badbit
{
   cerr << "Bad! Input bad!" << endl;//lol
}

or

string line;
string word;
string number;
ifstream inFile("somestuff.txt",ios::binary);
while(getline(inFile, line))
{
   stringstream ss(line);//stringstream from line.
   if( ss >> word >> number )
      cout << "OK.\n";
   else
      cerr << "Bad!\n";
}
pseudorandom21 166 Practically a Posting Shark

Oh heck I like reinventing the wheel.

For the project that uses boost::ip::tcp::iostream, I have a thread that reads lines from the server and a list of "hook" classes that operate on the information line by line.

Anybody else have a magic idea for an implementation?

pseudorandom21 166 Practically a Posting Shark

I'm now actually fairly certain it isn't a protocol at all, it just has an RFC and a bunch of implementations, I'd guess the server-end is documented more protocol-ish.

To be clear though, I'm trying to automate the entire process instead of having user interaction like knowing when to send the server a username, etc.

Want to see what I mean?
telnet to irc.freenode.org on port 6667 and it'll send a variable number of lines that differ from server to server, then you need to "register"

type "NICK naruekins" [enter]
"USER naruekins 8 * : Anonymous"

then it sends the MOTD and a bunch of other crap. It just isn't a strictly defined protocol, I'd have to wait a certain length of time after connecting to send my nick/user to make sure it reads all the intro BS so that I can receive and parse the error message (if any).

Also, I'm trying to automate the nick/user registration sequence.

pseudorandom21 166 Practically a Posting Shark
pseudorandom21 166 Practically a Posting Shark

I've been trying to make a reliable IRC client for a while now, and I know very little about sockets. I have read the RFC quite a bit, but programmatically responding when appropriate, and detecting errors still boggles me.

How is the program to know the server will send three or four lines before I should send the NICK/USER ?

It seems the only way is to make use of deadline_timers.

I have two failed IRC projects (actually they work, but they aren't good enough to suit me).

One uses boost::ip::tcp::socket's, and the other uses boost::ip::tcp::iostream.

It just seems as if the IRC protocol is a pretty bad one, if it is one at all.

Any tips?

pseudorandom21 166 Practically a Posting Shark

Is the name of the file actually "Dictionary" or "Dictionary.txt" ?

Also, with Vista above you actually can't read/write files in the root directory (C:) without admin priviledges.

Run your project as an administrator and see what I mean.

pseudorandom21 166 Practically a Posting Shark

If ASIO had better documentation I could probably have found for myself an answer, but instead...
Is there a way to determine bytes available to read using the asio::ip::tcp::iostream ?
I really like the tcp iostream because it's super-easy to use, but I haven't found it exactly feature-packed. Does it have a tcp socket in there somewhere?

pseudorandom21 166 Practically a Posting Shark

here is what i have for avg / total - how can i make this legal? right now i cant return avg/sum...

Book AverageTotal (Book index[],int s)
{
   int i;
   int sum;
   int avg;

   for (i=0; i<s; i++)
	   {
		 sum = sum + index[i].cost;
	   }
   avg = sum / i+1;

   return avg/sum;
}

I find it hard to believe you can't solve that problem.

double sum = 0.0;
for(int i = 0; i < s; i++)
{
   sum += index[i].cost;
}
return sum / s;

Now, what is the advantage to returning a "book" structure instead of a double?

Also I overlooked your use of the bitwise-AND operator (&) while ((i < s) & (ans != 'no') & (ans != 'No') & (ans != 'n')& (ans != 'N')); Please see my solution in an above post, or use "&&" (the logical-AND).

pseudorandom21 166 Practically a Posting Shark

I think it would make more sense as a for-loop.
Also the creation of a function to determine whether it's a yes or no would probably simplify things.

Sadly since you've said you can only use certain features of the language then your answer will probably suck.

Perhaps this will help:

bool GetAnswerResult(string answer)
{
	//if you must list every acceptable answer
	//why not use const strings?
	const string falseOne = "n";
	const string falseTwo = "N";
	const string falseThree = "No";
	const string falseFour = "NO";
	const string falseFive = "nO";
	//Work your magic here.
}

int filler (Book single[], const int s)
{
	string ans;

	for(int i = 0; i < s; i++)
	{
		single[i]=getitems();
		cout<<"Would you like to enter another book?(y/n)";
		cin >> ans;
		if( !GetAnswerResult(ans) )
			break;
	}
	return i;
}

Also, your naming system seems a bit flakey.
Pick a style and stick with it until you know better.

I still say use the first character of the y/n answer to determine the result.

pseudorandom21 166 Practically a Posting Shark

Post your code inside the code tags: [code] /* CODE HERE */ [/code]

Also, please preserve the formatting (posting in the code tags will do that). You will need to copy it from it's original source again.


Here's a tip for your "filler" function though,
read a line of input at a time and extract (parse) what you need from it.
The reason to do so is to avoid causing "cin" to fail and have junk left in the input buffer because the process of clearing the buffer and ignoring the garbage is different from platform to platform.
It's much easier to do this:

string inputLine;
getline(cin,inputLine);
if(inputLine.size() == 0)
   return;
char answer = inputLine[0];

Also there are useful character functions in <cctype> like "toupper" and "tolower".

string inputLine;
getline(cin,inputLine);
if(inputLine.size() == 0)
   return;
char answer = toupper(inputLine[0]);
if( answer != 'Y' )
   return;
pseudorandom21 166 Practically a Posting Shark

Will this help?

C++ tokens:

#include <iostream>
#include <string>
#include <sstream>
#include <vector>
using namespace std;

int main()
{
   string line = " some tokens and a  few 2349582346 2435  555 32 2 2 2 numb3r5";
   stringstream ss(line);
   vector<string> tokens;
   string temp;
   while( ss >> temp )
      tokens.push_back(temp);
   for(vector<string>::iterator it = tokens.begin(); it != tokens.end(); ++it)
      cout << *it << endl;
}
pseudorandom21 166 Practically a Posting Shark

Ctrl + X is sometimes a system command that may terminate or suspend the program.
On windows it's probably Ctrl + C.

pseudorandom21 166 Practically a Posting Shark

I am indeed using linux and I may give a try to your idea but I'd like my code to be as portable as possible.

So, I'd like to find another solution!

Thanks for the hint...

oooh sorry link fail!
lol, it was supposed to be a youtube video.
http://www.youtube.com/watch?v=ys4NjnSyzkY

pseudorandom21 166 Practically a Posting Shark

Hey if you're using linux why not give the C++0X threads a try?
http://www.cnn.com/video/?/video/cvplive/cvpstream1

I don't know how to use the pthreads library or I would be able to help more, sorry :(

pseudorandom21 166 Practically a Posting Shark

Are you allowed to use the C++ STL in this program? (vector, list, etc.)

pseudorandom21 166 Practically a Posting Shark

I think this is a terrible event, since when is LulzSec anyone's enemy (besides the government)?

They compromised the NASA website? Why?! LulzSec exposed a CIA botnet, why would the CIA have a botnet? Isn't this botnet preying on unsuspecting users? I don't want the CIA to have a botnet, what if they decide to launch attacks on websites we use, like Daniweb?

This secrecy is against the very foundation of a free society, and remains a danger to our civil liberties, Viva La LulzSec!

MosaicFuneral commented: . +0
pseudorandom21 166 Practically a Posting Shark

Initializing variables to zero.

float yards[32] = {0.0f},
      passyards[32] = {0.0f}, 
      points[32] = {0.0f};

If you're using visual studio you can set a "breakpoint" and debug the application.
See the link in my signature for a youtube video on it.

Chances are you aren't reading them from the file properly--or perhaps the float datatype doesn't have the capacity to hold such a large sum of numbers. Try a double.

pseudorandom21 166 Practically a Posting Shark

Well I found the solution but it isn't using "SELECT DISTINCT" which I had already tried...

For some reason:

DataView view = autoDealershipDataSet.tblCars.DefaultView;
            DataTable distinctTable = view.ToTable("DistinctMakeTable", true, "Make");

            this.tblCarsBindingSource.DataSource = distinctTable;
            this.tblCarsBindingSource.ResetBindings(true);

You can't use the Filter property of a binding source to select distinct items, there is a crappy work-around.

pseudorandom21 166 Practically a Posting Shark

I have a combobox I need to display some data in from a Database, but there are duplicates and I don't know how to select the distinct ones.

Any help?

pseudorandom21 166 Practically a Posting Shark

I have a form with a number of controls on it, and I had thought that the "Controls" property of the form instance contained all of the controls on the form as per the documentation.

Actually it does, but now iterating over all of my controls becomes similar to iterating over all the files in a directory structure, recursing subdirectories (groupboxes are now like folders).

So.. is there a generic algorithm for this in the standard library?

It could be a time saver knowing of this when using lots of nested groupboxes, btw.

pseudorandom21 166 Practically a Posting Shark

Thank you! Schoil-R-LEA

For pseudorandom21-What do you mean by two tokens?

Any group of non-whitespace characters is a token.

pseudorandom21 166 Practically a Posting Shark

It has occurred to me that there are very many factories in my area that use CNC (Computer Numerical Controlled) Lathes and other computer controller machinery.

Is the operation of this machinery typically a job for a software programmer or does it require specialized knowledge?

Is it worth doing with a degree?

pseudorandom21 166 Practically a Posting Shark

Last program of the class and you can't construct a for loop?

//Syntax:
//for( ; ; )
//for( <initilization, normally a loop-control variable>; <test expression>; <increment/decement> )
//As such it follows that:
for(int i = 0; i < 100; i++)
   cout << i << endl;
//is a valid count-controlled (with the loop-control variable) for-loop.
harde commented: Thanks man +0
pseudorandom21 166 Practically a Posting Shark

Perhaps I'm mistaken but I believe there are drinks with spaces in the name, I'm not aware of how your solution will properly deal with that.

After a lot of thought about dealing with strange drink names such as "7 UP" or "Coke 0" or something, the one solution that sticks out in my mind as the best is:

1) Remove the two tokens from the end of each line and cast them to their proper types, after which you will be left with the name of the drink.

pseudorandom21 166 Practically a Posting Shark

Thanks, can you show me an example cus ive tried everything to fix the loop but im stuck at a dead end.

You could perhaps try extracting the two values from the end leaving the remaining text...
Or just fix that loop so it finds the index of the last character, then create a substring for the name of the drink using that index--then parse the two values.

pseudorandom21 166 Practically a Posting Shark

instead of spaces or tabs use setw

#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
    cout << setw(10) << "First" << setw(10) << "Last" << endl;
    cout << setw(10) << "Somename" << setw(10) << "lname" << endl;
    cout << setw(10) << "Somename" << setw(10) << "lname" << endl;
}

Now I see that you have used it once, but in other places you have used a tab :/ maybe that isn't the problem but it's probably worth investigating.

This seems to be a poorly designed loop,

while(!infile.eof())
    {
        word= "";
        ch = infile.get();
        while(true)
        {
            if(isdigit(ch) || ch == '\n')
                break;
            else
                word += ch;
            ch = infile.get();
        }

What happens if no digits or newline is found at all? Infinite loop.

pseudorandom21 166 Practically a Posting Shark

The dox also say it's used to add events to the queue, so after you process one in main I suppose you can put it back on the queue...
Not sure how that will pan out though.

pseudorandom21 166 Practically a Posting Shark

SDL_PollEvent returns 0 when no events are left to process, perhaps this happens more often than you realize?

Also the nature of polling implies if you wait too long between polls (doing work in your switch) you may miss something.

pseudorandom21 166 Practically a Posting Shark

Perhaps you would prefer to use an STL container like a deque or vector?

http://www.cplusplus.com/reference/stl/deque/
http://www.cplusplus.com/reference/stl/vector/

Both containers appear to provide random access iterators and a dynamic size.

pseudorandom21 166 Practically a Posting Shark

diffuse

I expect you meant defuse :) I know, I just can't stop.

No he surely intended to add a haze of fog to our stupidity as that's the only solution.
Now it's just *Everywhere* =D

pseudorandom21 166 Practically a Posting Shark
pseudorandom21 166 Practically a Posting Shark

Also, just out of the blue--what if you used a C++ Map?

You could store your operator precedence rules as a value in the map:

std::map<char,int> OperatorMap;
OperatorMap.insert( std::pair<char,int>('(',100) );
OperatorMap.insert( std::pair<char,int>(')',100) );

With something like that you could potentially start your operator precedence at 100 and work your way down, and use the operator's mapped value to determine precedence.

if( OperatorMap['('] >= OperatorMap[')'] )
    ;//
pseudorandom21 166 Practically a Posting Shark

Post your code inside the code tags (available on most forums):
[code] /* code here */ [/code]

For your "IsOperand" function there are some functions in <cctype> that you may want to look into using, particularly isalpha() and isdigit(). Alternatively you can build an alphabet as a string and use it to test your character against, ex.

const std::string OperandAlphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
char ch = 'a';
return (OperandAlphabet.find(ch) != std::string::npos);

Looking at your approach to most of the functions you've written I think the simple alphabet tip may help you avoid a lot of tedious work.

pseudorandom21 166 Practically a Posting Shark

void main()

Use int main() or int main(int argc, char *argv[]) as your entry-point, "void main" is not and never has been valid C or C++.

void DisplayBelowAverage( const string; const int[]; int, double);

replace ';' with ','.

void DisplayPlayerData(playerNameAr[], scoreAr[], numPlayers)

that is not valid as a function header!


Take this for example:

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

//Function prototype/declaration.
void PrintSomething(string[], int[], int);

int main()
{
   string stringArray[128];
   int intArray[128] = {0};
   PrintSomething(stringArray,intArray,1000);
}

//Function definition.
void PrintSomething(string someLocalFunctionName[], int otherFunctionLocalName[], int n)
{
  if(someLocalFunctionName != NULL)
    ; //etc.
}
pseudorandom21 166 Practically a Posting Shark

That seems kind of silly to me. The point of a checksum is to verify the legitimacy of a file after downloading it. If you're getting the checksum before downloading the file it's no different from taking on faith that the file is legit in the first place.

Regardless I'm looking for a way to get the checksum without downloading the file.

pseudorandom21 166 Practically a Posting Shark

Counter Strike Source Beta sounds like a good game to be a bodyguard in, just for shoots and giggles.

pseudorandom21 166 Practically a Posting Shark

Anyone know of a way to obtain an MD5 checksum of a file (through HTTP) before downloading it through HTTP?

pseudorandom21 166 Practically a Posting Shark

A gigantic complicated MS Access database and a C# GUI for manipulating data, and then generating crystal reports.

pseudorandom21 166 Practically a Posting Shark

Post your code inside of code tags:

[code] /* code */ [/code]

pseudorandom21 166 Practically a Posting Shark

If you or anyone you know is on the needy list this winter, you may want to sign this petition:

http://wh.gov/jyC

Hey it's better than Obamacare and it might actually help some people.

pseudorandom21 166 Practically a Posting Shark

Yes you can:

1)
Write the "move" function so that it operates properly using the "WARRIOR" information.
ex:

const std::string WARRIOR = "Warrior";

class Character
{
public:
std::string Type;
void move()
{
   if(this->Type == WARRIOR)
     ;//move
}
};

2)
Redesign using polymorphism with a base class and a Warrior derived from it.
ex:

class CharacterBase
{
public:
virtual void move() = 0;//Pure virtual
};

class Warrior : public CharacterBase
{
public:
virtual void move()
{
   //Move your warrior.
}
};

void MoveCharacter(CharacterBase *myChar)
{
   myChar->move();
}

int main()
{
  Warrior myKnight;
  MoveCharacter(&myKnight);
}

3)
Use a function pointer or functor.
ex)

typedef void (*MoveFunc)(void);// named type for my func. pointer

void MoveWarrior()
{
   //etc.
}

class Warrior //redundant, etc.
{
  MoveFunc moveFunction;
  public:
    void move()
    {
      moveFunction = MoveWarrior;
      moveFunction();
    }
};

Please excuse minor bugs.
Also, there are a large number of other strange things you can do with C++ so you're pretty well-off on finding a way to do it.

pseudorandom21 166 Practically a Posting Shark

I'm not sure I entirely understand your question.

You would like to define a string constant, correct? const char *WARRIOR = "Warrior"; -or- const string WARRIOR = "Warrior";

void play(char gameWorld[][BOARD_SIZE])
{
	Warrior war(1,1);
	int userChoice = getUserChoice();
	string currentPlayer = WARRIOR;

	while(userChoice != 'q')
	{
		switch(userChoice)//<--
		{
		case(50): //<-- what?
((string)currentPlayer).moveDirection(DOWN);
		}
		userChoice=getUserChoice();
	}
}

The "switch" is a cleverly disguised specialized if/elseif, and it's fairly primitive. You might find it easier to use if/elseif/else.

pseudorandom21 166 Practically a Posting Shark

You can do that with a registry entry, the location fails me at the moment.
Also you can use the task scheduler to do it (preferred).

pseudorandom21 166 Practically a Posting Shark

Here is the 'dirty' side of the libertarian 'utopia':

Schooling will be entirely privatized the bottom X% for which industry calculates it is not profitable to serve will be incapable of getting even the basic education to read and write. Similarly that same bottom X% of the population will have no access to medical care because increasing the price beyond their means to pay it will be more profitable, Unfortunately this means diseases previously controlled by routine vaccines will beable to resurface (since many require a very high immunity rate for herd-protection to control it) eg. measles, mumps, whooping cough and new ones evolve (eg. bird flu).

This bottom segment of humanity will rightly feel they have no chance of escaping poverty since they will be unable to get a job (being illiterate and all) thus with no EI they will be homeless and living in ghettos likely involved in various forms of crime. Since these same people will not be able to afford firefighters (or indeed running water) when these ghettos catch on fire they will become a huge bonfire likely taking out neighbouring buildings and the air pollution created will affect even the richest members of society. Since EI will have been abolished any worker unfortunate enough to lose his job due to downsizing as high-tech and high-skill jobs begin to flee (highly skilled people generally don't like living near ghettos or in cities you're afraid to walk down, plus the lack of basic research will cause innovation …

pseudorandom21 166 Practically a Posting Shark

Was thinking of the C++ primitive types,
Not that funny actually.

pseudorandom21 166 Practically a Posting Shark

If the US gov't shut down, basically all public sector employees would stop being paid and all gov't services would be shut. This includes
some low importance things like passport offices,
some moderately important things like EI, pension payments, research/scholarship payments, the military, prisons,
some highly important things like border controls (shut down of international trade and tourism), police, firefighters, medicare/medicaid,

As for funding cuts I doubt they would cut CIA/FBI but EI/pensions, education, medicare/aid, prisons and military spending would probably be cut to various degrees. Education and military spending cuts would probably guarantee a huge loss of public sector jobs (add a couple of percentage points to the unemployment), reducing the pensioners to poverty and without health-care, and releasing many prisoners back into society (and many laws would cease to be enforced).

Although IMO it wouldn't come to that, I think its much more likely they would instead turn on the presses and risk hyper-inflation.

That's not a smooth takedown though, I would think the process is defined somewhere?
It probably should be...

pseudorandom21 166 Practically a Posting Shark

I'm not talking about the files being compressed on your machine; rather, I mean as part of the FTP protocol. It might be possible to request that FTP compress your file before transfer, uncompress upon receipt and then deliver it to your application. This would allow for less bytes over the wire while still appearing as full-size on your machine.

He said he measured the bytes transferred somehow, but I don't see how he would know legitimately from someone else's client.

pseudorandom21 166 Practically a Posting Shark

If you wouldn't mind using QT I suppose you could try:
http://doc.qt.nokia.com/latest/qftp.html

One word of advice, I would recommend using the QT installer on Windows, definitely.

Alternatively there are other projects,
http://sourceforge.net/projects/poco/

As for the command line arguments,
as you probably already know char *argv[] contains the command line arguments, but it will separate them when it encounters a space and all sorts of other ancient behavior ( the '>' character redirects the output, etc.) so you might want to bone up on that aspect first.

pseudorandom21 166 Practically a Posting Shark

Of course they will probably work out a solution, but what will happen if the U.S. government shuts down?

http://money.cnn.com/2011/11/18/news/economy/debt_committee/index.htm?source=cnn_bin

What parts of defense and nondefense spending will be cut automatically?
What about agencies like the CIA and FBI?
What about military funding for the Army and such?