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

>>I tried changing the path but got lods of errors.
Post what you tried. Basically, its nothing more than this: char* path = "c:\\mydir\\myfile.txt"; . Note the double backslashes.

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

You get errors because all you wrote was crap. Look at that first line and change it to the way I had it.

>>and the only reason I didn't change that one part is because it works fine the way it is.
You mean it compiles ok -- it doesn't work at all, which is why your program doesn't display anything.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
spnVqw.push_back(SPNstruct(sztempeng,sztempspn));


		for(int i = 0; i < 55; ++i)
			inStream.getline(sztemp, 1000);

I rember telling you this in an earlier thread -- that code is NOT loading the strings into the vector. All it does is read each line from the file ( using getline) ) and does nothing with the lines. Here is how to fix it

for(int i = 0; i < 55; ++i)
{
     inStream.getline(sztemp, 1000);
// now split the line into both english and spanish translations
// I don't know how to do that so you'll have to figure it out yourself.
//
// now add both translations to the vector
     spnVqw.push_back(SPNstruct(sztempeng,sztempspn));
}

The classs constructor is also want. It needs to allocate memory for the two strings then copy them.

SPNstruct(LPCSTR english, LPCSTR spanish) 
{ 
    eng = new LPCSTR[strlen(english)+1];
    strcpy(eng, english);
    // now do the same thing for spn variable
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you might have to go with something like OpenGL or wxWidgets, both have *nix ports (I think)

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

please post the input file(s) (books.txt, tokens.txt, etc.) It appears the reading of tokens.txt is doing an awful lot of unnecessary work by reading the file one character at a time instead of using getline() to read the entire line into a std::string object. If you want to strip comments then just use string's find() method to check if '//' or '/*' comment exists.

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

>>Unfortunately I throught of this question at work this morning while trying some of the practice problems on this site.

Oh?? Your boss doesn't mind you cheating him?

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

>>will the value of counter automatically change as well?
No because they are two different variables. Line 10 only initializes the value of counter to be the same as number. From there on the value of counter does not change.

>>what is the best way to create a variable that will hold the original value of number
You don't have to do anything more because your program already does that.

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

Are you sure that compiler has that limitation? If yes, then you might try using win32 api functions as in this thread

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

You will have to write your own function. But its pretty simple

int main(int argc, char* argv[])
{
    std::string str = "Hello\\nWorld\\\\nAnother\\nWorld";
    size_t pos = 0;
    while( pos < str.size() && (pos = str.find("\\n", pos)) != string::npos)
    {
        if( str[pos-1] != '\\')
        {
            str.replace(pos,2,"\n");
        }
        else
        {
            // advance past "\\n"
            pos += 2;
        }
    
    }
    cout << str << "\n";
	return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I created a 1.2 gig text file that contained 10-character words (generated randomly). Then tried to read it into a std::list. The program crashed after reading just over 24 million words. Changed the program to use deque instead of list, and it read even fewer words before crashing. (my computer is running vista home, has 5 gig ram, and used vc++ 2008 express compiler/IDE)

Of course it would have been easier to check by calling the list's max_size() method. For deque

maxsize = 134217727
Press any key to continue . . .

Changed the program to use try/catch and got this:

23020000
23030000
Out of memory

// final size of the deque
size = 23031567

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

>>I have 8 gigs of ram, so I know it's not running out of space

32-bit programs can not access all that memory at one time. Each 32-bit program is limited to about 2 gig ram.

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

Okay, it works now, however, if the string has any spaces in it, it doesn't work.

Does anyone know how to add spaces to a string variable?

Thanks for all the help :)

You could have saved yourself a lot of time had you bothered to read the post I made over 10 hours ago :icon_eek:

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

Didn't bother me a bit because I don't use either :) When I want to talk to someone I do it the old-fashioned way -- face-to-face, or ear-to-ear.

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

Normally overload operators so that you can do mathematical or other operations with c++ classes. for example: cout << MyClass; assuming MyClass is an instance of some c++ class and you want that class to print the value of its class variables to the screen. Or you might want to add them MyClass++; There are lots of things you can do with overloaded operators, those are just two of them.

Which operators to overload depends on the c++ class and what you want it to do.

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

vector<vector<char>> vset; //that should be an error because of the
confusion of the stream operator >>. Need space between them.

That might be true of older compilers. VC++ 2008 Express says its ok, but I do recall some compilers having problems with it.

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

So?? All you have to do is pass the char* of string. chdir(cFolder.c_str(); . And note that the >> operator will not allow spaces in whatever it is that you type. call getline() if you need the spaces.

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

There is quite a bit of overhead, but you can use some of the VUL functions of VXL.

?? why ?? All he needs is chdir() function.

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

You are attempting to treat a <vector> as if it were a <set>, which is not possible.

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


int main()
{
    vector<vector<char>> vset;
    vector<char> element;
    vset.resize(255);
    element.push_back('a');
    element.push_back('b');
    element.push_back('c');
    vset['A'] = element;
    element[0] = 'e';
    element[1] = 'e';
    element[2] = 'f';
    vset['B'] = element;

    vector<vector<char>>::iterator it1 = vset.begin();
    for( ; it1 != vset.end(); it1++)
    {
        if( !(*it1).empty() )
        {
            vector<char>::iterator it2 = (*it1).begin();
            for( ; it2 != (*it1).end(); it2++)
            {
                cout << *it2 << " ";
            }
            cout << "\n";
        }
    }


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

The system function will not work for what you want to do because as soon as system() returns to your program the operating system discards the results of cd and resets the current directory to what it was before the program called system(). This is the same identical behavior of *nix operating systems and *nix shells.

The only way to make your program work is to call the standard C function chdir(), as previously recommended (assuming your operating system supports it, and some do not.)

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

If you are using *nix then use opendir() and readir() functions. You will find examples here.

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

Here is one way to do it. Make sure the list is separated by tabs, not spaces. You could also make it a comma-separated list and this word work with it too if you replace '\t' with ','

What this does is build a vector of questions. Each Question class contains a vector of answers. By using this method the file can have an unlimited (almost) number of questions, and each question can have an unlimited (almost) number of answers.

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <sstream>
using namespace std;
#pragma warning(disable: 4996)


class Question
{
private:
    string q;
    vector<string> answers;
public:
    Question(string& line);
    Question();
    string GetQuestion() {return q;}
    vector<string>& GetAnswers() {return answers;}
};

Question::Question(string& line)
{
    string word;
    stringstream str(line);
    // extract the question
    getline(str,this->q,'\t');
    // now extract each of the answers
    while( getline(str, word, '\t') )
    {
        if( word.length() > 0)
            answers.push_back(word);
    }
}

int main()
{
    string line;
    ifstream in("file.txt");
    vector<Question> questions;
    if( in.is_open() )
    {
        while( getline(in, line) )
        {
            Question q(line);
            questions.push_back(q);
        }

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

Line 15 of your original post is wrong because Process is not a function pointer.

int main( int argc, char* argv[] )
{  
EnumProcesses(CrapFunc);
  return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
int main( int argc, char* argv[] )
{  
    char* inputFile;
    char* outputFile;
    inputFile = argv[ 1 ];
    outputFile = argv[ 2 ];
    ifstream in(inputFile);
    if( in.is_open() )
    {
        ofstream out(outputFile);
        out << in.rdbuf();
    }
    //ofstream(outputFile) << ifstream(inputFile).rdbuf();
  return 0;
}
Nathan Campos commented: Thanks very much, you're a very good man! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you are using MS-Windows you can call win32 api functions FindFirstFile() and FindNextFile() to get a list of all the files. Then for each of the filenames it returns just select the ones you want to copy. See this example.

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

First, open the file for reading in binary mode.
Second, open the output file for writing in binary mode
declare an unsigned char array of size 255

create a while loop and continue while reading

while( infile.read( buf, sizeof(buf) )
{
    size_t len = infile.gcount(); // get the number of bytes read
    outfile.write( buf, len );
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

google for "odbc tutorials"

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

There are a couple ways to use SQL databases such as MS-Access. 1) ODBC and 2) ADO

Since you didn't bother to tell us what you did or post any code, I'm not going to bother explaining how to do it other than giving you some google links.

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

Also, the fact that like most democratic nations, voting is compulsory (a fact I know the Yanks find hard to fathom)

Yes, nearly 100% of the citizens of Iraq voted and Saddam Hussein won 100% of those votes during the "election". But I would not have called that a democracy. Dictatorships are sometime disguised as democracies.

Hiroshe commented: Good point. +4
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Glad to know its not my imagination :)

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

I was also having problems today setting up NetBeans with MiniWG. Even after installing the MSYS version of make, NetBeans refused to successfully compile a simple Hello World program. So I deleted MiniWG and installed cygwin, and had everything going in about a half hour. I have not tried debugging yet, so I can't help you with that.

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

>>i think you can understand what the assigment about.
That is an invalid assumption. How can I possibly know what the assignment is about if I have not attended your classes or read the assignment paper ???

>>But actually i din not understand what tick mean is
Neither does anyone else. Could the the tick of a clock, or a nasty creature you pick up on wooded areas (wood ticks).

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

>>It seems that there is 10 3's in every 100;
There are 19 numbers between 1 and 100 that contain one or more 3s. 3 13 23 30 31 32 33 34 35 36 37 38 39 43 53 63 73 83 93 I thought about the mod operator too, but it won't work. Example: Enter max num = 100. 100 % 100 == 0, which is clearly wrong answer.

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

to put code tags, do this :

(code) (/code) , except delete and leave no space in between.

You don't read very well, do you.:'(

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

Since we don't have the assignment I can only guess (give it my best shot).

Particle::Particle(double mass, Vect3D &location, Vect3D &velocity) {
	
}

All you have to do here is initialize each of the class variables with the parameters.

void Particle::applyForce(Vect3D&v) {    
	return;
}

void Particle::tick(double seconds) {
	return;
}

I don't have any idea what those two functions are supposed to do.

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

Yes :)

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

>>"(1) how to capture number of occurrences of 3 between 1 to 100? "

Write a for loop that counts from 1 to 100. Convert each int value to a string then test the string if it contains a '3'.

2) Do you know how to declare a function pointer? Almost like declaring a function prototype. For example, if you have a function that takes an int parameter and returns an int, then a function pointer might be int (*fn)(int);

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

Go back to your original post, hit the "EDIT THIS POST" button, then put [code] before the first line and [/code] after the last line. You will see the difference.

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

main() is passing an array of ints to that function, but the function is using it like its a pointer to a single int.

>>The code is taken from Dennis Ritchie's "C Programming Language" 's page 97 (2nd Edition).
I doubt it -- he is a hell of a lot better programmer than that!

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

You won't get much help by posting all that unformatted code. Learn to use code tags. You still have time -- go back and edit that post to add the tags.

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

It is almost impossible in your country to remove a defective president no matter how bad things get (with the exception of being impeached for serious breach of ethics or laws) - and thus you assume the same is elsewhere.... and wrongly so.

Agree with that statement -- its too difficult for us to remove a President from office. But I don't know any alternatives -- our government does not have a monarchy who can dissolve congress and force a re-election.

Like most democratic nations, the Prime-minister cannot simply decree a law or political policy at whim. Here, the senate actually has the power to block any decision the Prime-minister proposes. Thus there is a check-and-balance written right into our democratic/political system far beyond what the US enjoys.

Why do you not believe the same checks-and-balances are not available here in USA? What exactly are the laws you think our President makes? Our President, like your Prime Minister, can not just make laws as he sees fit. Only Congress can make laws -- the President can only carry them out.

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

That will be too slow. If you are on Windows os then try this function

Or maybe this program.

And I hope you intend to use the same file every time. You will fill up a hard drive pretty quickly if you use a different names.

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

A while back when I changed and saved my signature it was changed on every post that I had made. I just now changed it, but nothing happened in existing posts. Was the previous behavior because I was a mod or has something else changed here at DaniWeb ?

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

I had already installed cygwin, but based on your recommendations I deleted it and installed Code::Blocks with MiniGW. Code::Blocks appears to be working now. Then I tried to configure NetBeans to work with the MiniGW that's in Code::Blocks directory. The problem now is that there is no make.exe in that directory. So being the smart ass that I am I downloaded GNU Make for Windows, configured NetBeans to use that program. Apparently that version of make doesn't like the makefiles that NetBeans generates because it produced some sort of error.

make: *** [.validate-impl] Error 255

Anyone have a solution to this problem? Or know why a make.exe program was not installed with MiniGW?

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

Suggest you use getline() to read the entire line, then use stringstream object to split it into words.

std::string line;
ifstream in("file.txt");
while( getline( in, line) )
{
     std::string word;
    stringstream str(line);
    while( str >> word )
    {
       // now do something with this word
    }
    
}

As for the quotes -- you will have to parse the word and strip them out if they exist.

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

right click on the project name, then select Properties at the bottom of the menu. In the Categories box select Linker, then on the right side click the button with "..." next to "Libraries" (near the bottom) , In the popup window select "Add Library" and there you can add ws2_32.a

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

I see folks replying to threads with quotes that have the name of the original poster included - they have the form

nameOfPoster> quote

I've been crawling around the faq for the past hour or so, and haven't found any really newbie guides for using all the neat stuff that's available for doing that, for using code tags, etc. I'm sorry for this really dumb question - although I'm old in years, I'm very new to online forums and would like to be able to use this one sort of intelligently. Have I been looking in all the wrong places?

Thanks so much!

All you have to do is hit the "Reply W/Quote" button.

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

I'm trying to set up NetBeans IDE on my Vista Home, and have a choice between those two compilers. Which one would you choose? I also want to have Code::Blocks.

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

Get the input as a string then check each of the characters. If all is ok then convert that string to int (or other data type). Something along these lines.

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

int main()
{
    int gallons;
    std::string input;
    cout << "Enter gallons\";
    cin >> input;
    bool ok  = true;
    for(int i = 0; i < input.length(); i++)
    {
       if( !isdigit(input[i]) )
       {
            cout << "Error\n";
            ok = false;
       }
   }
   if( ok == true )
   {
         stringstream str(input);
         str >> gallons;
   }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Never was sure why the creators of the low level ODBC Api had to use those odd redifinitions of char.

Probably because its platform and language independent. SQLCHAR might be defined as something other than unsigned char on other platforms or computer languages.

And there are already c++ wrappers.