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

You have to write the code that iterates through all the files in the folder and sum up their sizes. boost library doesn't do that for you. I could easily write such a program without boost, but I doubt that is what you want. You need to write a function that iterates through all the files and directories, then when a directory is found call that function recursively to process all the files in the sub-directory. I posted a code snippet a couple years or so ago that does just that using win32 api functions.

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

32-bit vc++ 2008 express on 64-bit Win7 doesn't have that problem.

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

int main()
{
   // use textual representation for bool
   cout << boolalpha;

   // print maximum of floating-point types
   cout << "max(float):       "
        << numeric_limits<float>::max() << endl;
   cout << "max(double):      "
        << numeric_limits<double>::max() << endl;
   cout << "max(long double): " << fixed 
        << numeric_limits<long double>::max() << endl;
   cout << endl;

}

output

max(float): 3.40282e+038
max(double): 1.79769e+308
max(long double): 17976931348623161000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000.000000

Press any key to continue . . .

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

Homework? You answer the questions and we will tell you whether you are right or wrong.

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

Use your compiler's debugger and step through the program one line at a time.

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

you put it in the wrong place. Check the file size on line 39 (inside the else statement). It would make your program a lot easier to follow if you wrote another function to return the file size.

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

You need to stop the second loop after the first printf()

for (d=2;d<b;d++)
    {
        f=c%d;
        if ( f == 0)
            break;
        if (d>=a && d<=b)
        {
            printf ("%d ",c);
            break;
        }
    }
Xufyan commented: thanks :) -> xufyan +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

If you run that from command prompt how to you know it isn't opening the file? There is nothing in your program that will tell you whether the file is opened or not. Opening the file will not display its contents on the screen. You have to add more code to do that.

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

are you trying to print all the odd numbers between two values? Your program is doing much too much work! It only needs one loop, not two. Delete that second loop and just test if the loop counter d is even or odd.

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

>>player1score = add10 (player1score);

The first example doesn't work because it never changes the value of player1score variable. In the above code, when add10() returns it assigns the return value to player1score. That is not done in the first example. Passing a variable by reference does not do anything if the function does not change its value. Modify the first example like this and you will see the difference

int add10 (int &score) // function that adds 10 to player1score variable by reference
{
      score += 10;
      return score;
}
nats01282 commented: excellent answed my question first post +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Thanx for the reply.

Tho I'm not sure I understand...

I can list all the files in a directory. Or get a specific file size if i give it a specific file in a directory. So can't I just loop thru the directory and print out the size everytime it finds a file?

.

You mean you don't know how to put the two together so that you can get the size of all the files in a directory? Odd.:-O

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

Why are you multiplying nrows * sizeof(int*)? AnsiStriong is not an int pointer, so that doesn't make any sense.

>>AnsiString **array = new AnsiString*[nrows * sizeof (int*)];

^^^ Wrong AnsiString **array = new AnsiString*[nrows]; >>array= new AnsiString[ncolumns * sizeof(int)];

^^^ Wrong array[i]= new AnsiString[ncolumns];

Salem commented: Nice +20
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

call win32 api function CreateProcess() and you will have a lot more control over how the new process is created. Never tried it with a *.py program.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Freaky_Chris commented: Excellent resource +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

It's probably time for you to invest some $$$ and buy a good c++ book that covers a lot more than just the basics. Just because it will contain a chapter or two on data types, loops, etc doesn't mean you have to actually read them. Just skim over the parts you already know and concentrate on what you don't know.

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

You can not call malloc() to allocate c++ classes. It doesn't work. Use the c++ new operator. You have to call either delete or delete[] to destroy it.

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

The program depends.exe distributed with the compiler will tell you all the DLLs that are required by your program. Probably one or more of them are missing or the wrong version.

mitrmkar commented: A good suggestion. +5
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Second problem: Borland and Microsoft may have very different implementations of std::list, so the two may or may not be compatible.

Found out there are two different implementation of the same interface: one of them is in Visual C++, the other in Borland. One pointer created on one side has no meaning on the other end; that's why the program crashes; the approach wasn't the correct one.

**sigh** why did I waste my time with this.

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

You have to iterate through all the files in the folder and sum them up. See the link I gave you earlier because boost has a function to do that.

[edit]^^^ beat me to it :)

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
char answer;
cout << "Enter Y or N\n";
cin >> answer;
cin.ignore(); // ignore '\n'
answer  = tupper(answer); // convert to upper case
if( answer == 'Y')
{
   // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

what compiler are you using and on what operating system? Suggest you google for that error message and you might find the problem.

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

>>strftime(date,3,"%W",&tim);

Why? the tm structure already contains the weekday in numeric form. Just use it.

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

Check the result of scanf(). Maybe the last line of the file is a blank line.

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

>>Where would the std::list implementation reside?

<list> header file. There may or may not be a *.cpp file. If there is then you will not have access to it unless you paid $$$ for the source code.

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

No. I have no clue what "peteranswers" is.

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

put print statements on line 26 to show the value of dir1 and dir2. Most likely one or both are not formed correctly.

>>and i have infinite loop
Because the cin >> check; leaves the '\n' in the keyboard buffer which you need to remove

cin >> check;
cin.ignore();
// the value of check wlll be '1', not 1.

The above may or may not flush all the keyboard input buffer, expecially if you type a lot of other characters besides the integer.

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

Here is a good example of why threads should NOT be closed, and resurrection can be helpful to everyone. But this is an exception because most dead threads are not worth resurrecting.

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

What amazes me is each and every company can save you hundreds by switching from one of the others. That basically means you sign up and the insurance company gives you a $300 check! Then you can switch again and get $700 from the new one. It's a really useful thing!

Yea I wish they would put their money where there mouth is and send is a check for the difference :) But they aren't really that stupid. They just think we (the consumer) are -- and many people actually fall for all that crap.

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

lines 24 and 25: you may have to put '\' between them if the first string doesn't already end in '\'

line 30. This two parameters are wrong. First you don't even need those two pointers. CopyFile(dir1.c_str(), dir2.c_str()); No are not paying attention to what other people are telling you or not comprehending the importance of their comments.

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

Did you see this example?

I see boost::filesystem has at least one redeeming value -- a platform independent way to get a list of all the files and directories.

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

It works just as I said before. The code snippet you posted is C code

You, the programmer, are responsible for writing the body of that Read() function. Apparently you told vc++ you wanted that to be a member of the ATL program you are writing (or someone else write for you).

The first parameter is a pointer to a long integer. Because it is [IN][OUT] its value must be set before passing it to Read(). The Read() function might use that for something and change its value to something else. What it does, I don't know since you didn't post the whole function.

The second parameter is a long integer passed by value because its only [IN].

The third parameter is [OUT], and looks like a buffer to hold some data results. The Read() function will most likely use it to read a file or something into that buffer.

The last parameter [RETVAL][OUT] is a BSTR which Read() will set to something. RETVAL is similar to [IN][OUT], but a function can only have one RETVAL parameter. Not sure myself why, except that's just the way it is.

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

Memory allocated in a DLL must be released in the same DLL. Memory allocated in the main *.exe program must be released in the main application program. You cannot allocate memory in the DLL and release it (delete or delete[] or free() ) it in the main application program. So if the DLL populate the std::list then it must also destroy it.

Second problem: Borland and Microsoft may have very different implementations of std::list, so the two may or may not be compatible.

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

>>am i correct?
No. The function will use the parameters as described by IN, OUT or INOUT. That says how the parameters are used by the function. For example, if the parameter is INOUT then you need to set the value of the parameter then pass a pointer to it. For example the function could be something like this. Note that INOUT is in comments because there is no such c++ keyword.

BOOL foo( /*INOUT*/ int* n)
{
   *n = *n * 5;
   return TRUE;
}

int main()
{
    int x = 2;
    BOOL b = foo(&x);
    cout << "x = " << x << '\n';
}

If you are writing COM/ATL program using VC++ compiler then you might find IN, OUT, and INOUT keywords in the *.idl file, but that is a different language -- not c or c++.

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

I don't use boost -- just as easy to use fstream which is standard on all (or most) platforms that have file systems and c++. I see no point in using boost to replace fstream.

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

It is no trivial thing to do. Read the link I posted because it contains a few examples.
1) call CreateFile() to open the port
2) Set the port configuration (data bits, stop, bits, parity)
3) Check if anything is at the port, it there is then call ReadFile() to read it. If you use overlapped mode MS-Windows will call your function when data is available at the port.

That is all explained in the link I posted above. Study it carefully.

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

The structure st is wrong and you don't need to malloc() anything. Actually you don't need that structure at all unless you intend to add some other members later on.

abc.txt -- is it a text file (you can red it with Notepad) or a binary file (Notepad just shows junk on the screen) ?

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

Most likely your program is losing data because it does not have an interrupt driven input driver. If you used win32 api functions you would not have that problem. See this article

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

Also that last line is missing a comma printf("\n %d %c ",array[i],array[i]);

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

You have stated your assignment (probably homework) but you didn't state your question(s).

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

The way I understand the problem, the array does not have to have 10000 elements -- 10000 is just the maximum value that any one element may contain. In otherwords you have to generate an array that contains N elements (allocate with new operator), the value of each element is randomly selected between 0 and 10000.

After you find out the value of N, allocate an array of N integers then populate it with values between 0 and 10000. You can use array[i] = rand() % 10000; in a loop.

After that, you need another loop from 0 to Q. In that loop you need to generate another random number between 0 and 10000 then try to find that number in the array.

Of course, I could be all wrong about the problem too :)

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

Could be one (or both) of two problems:
1) The destination can not be just the path, but the path + filename. The destination filename may be the same as the source filename or something else if you want to rename it.

2) You may not have permissions to write into the destination path.

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

you will need a file extension too.

Maybe, and maybe not. Depends on if the file has an extension, and what the actual extension is. Could be *.txt, for might also be something else, or nothing at all. Under MS-Windows XP or newer and *nix it may even have multiple extensions, such as "myfile.abc.efg.txt", in other words filenames may contain more than one period or no periods at all.

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

See the code snippet I gave you. getline() will let you enter it at the keyboard. If you don't want to type it then you can do this: ifstream in("C:\\Documents and Settings\\user\\Desktop\\myfile");

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

Well there isn't much to it

int main()
{
   std::string filename;
   cout << "Enter a filename\n";
   getline(cin, filename);
   // now open the file
   ifstream in(filename.c_str());
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

cruise.h is something you made up, so you'll have to post it if you expect any help.

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

Don't understand the question. The code snippet you posted looks perfectly ok to me (other than the obvious that its not in a function and missing the last } character)

Did you bother to compile and run the program to see what it produces? If not then you should do so.

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

Note that the terms "IN", "OUT", and "INOUT" are just a description of what the parameters are used for. Only for human consumption and mean absolutely nothing to the actual program or function. When you learned C or C++ language you did not use those terms, but you did learn the same functionality. You can normally just ignore the terms IN, OUT and INOUT and just concentrate on what the function does, what parameters to pass, and what the return value(s) is(are).

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

>>int abc(void);

That is called a function prototype, which is used to forward declare the function so that the compiler knows what it is, it's return value, and its parameters.

Function prototypes are unnecessary if the function actually appears before it is used, as in the example I posted. You may code the prototype, but it is not required in that case.

The code you posted does not compile because you did not code the function prototype correctly. Change it to this: int abc(float *b); Now change the actual function like this:

int abc(float *x)
{
float p;
scanf ("%f",x); // NO & symbol here because x is already a pointer
// Here is another way to code it
// maybe it makes more sense to you
// what it is doing.
p = *x;
return p * p;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Seek to the end of the file and call tellg(), or whatever function boost used to return the current file position.

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

A file can not be opened by merely giving fstream the path. It also need the filename. And use fstream's open() method. Search the net because there are billions of examples.

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

line 14: That declares an array of MAXSTRLEN number of pointers. Its not a character array. Remove the *.

line 21: There is no need for the typecast.

line 22: There is no need to increment both variables i and count because they both have the same value.

line 24: make sure to null terminate the string.

lines 28-31: Why print the string one character at a time? Waste of good cpu time and bandwidth. Just print it all in one shot printf("%s\n", str); lines 34-38. That does nothing. No conversion is needed to display either character value or decimal value.

line 48-52: That could be done by using array str directly

for (i = 0; str[i] != '\0'; i++)
   asciiArr[str[i]]++;