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

I have a question regarding coping of files:-

Is there any difference between Ancient Dragon's style of coping each byte at a time by looping through till EOF and azjherben's style of coping in one shot? I mean to ask about efficiency and all.

I think azjherben's would be faster and more efficient.

Need comments on this.

Thanks,

Copying everything in one shot is ok for small files that will easily fit in memory at one time. But will not work with huge files. I did not intend to suggest copying one byte at a time, but copying a buffer full, normally 255 bytes, at a time (depending on the sector size of the hard drive). Efficiency will depend on the operating system and how it handles buffered i/o. Some operating systems will not physically write to disk until its internal buffers are filled up. Similar with read requests -- the os might read a lot more data from the disk than requested in anticipation of another read request from the adjacent area (dick sector).

Luckychap commented: Well explained +3
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I just installed BCC55 compiled and ran your program with no problems. Here's what I did

C:\Borland\BCC55>bcc32 main.cpp
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
main.cpp:
Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland

C:\Borland\BCC55>dir *.exe
 Volume in drive C is HP
 Volume Serial Number is FA09-7490

 Directory of C:\Borland\BCC55

05/25/2009  08:54 PM           114,176 main.exe
               1 File(s)        114,176 bytes
               0 Dir(s)  526,502,633,472 bytes free

C:\Borland\BCC55>main
Hello world!

C:\Borland\BCC55>
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you have to seek to the end of the file before calling tellg(). When the file is opened the file pointer is at the beginning of the file, not the end.

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

Is there a question there? Or are you just posting your code because you are very proud of it?

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

Steps

  • Open original file for input, in binary mode std::binary as second parameter
  • Open output file for writing in binary mode
  • Create an unsigned char array for i/o
  • In loop call ifstream's read() method to read , then write the buffer using ofstream's write() method, until end-of-file.
  • Close both files
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

try pre-declaring the classes in the header files, but that works only if the object you want to use is a pointer. So you would probably have to change GLCursor MovementCursors to a pointer GLCursor* MovementCursors; [edit]what ^^^ said :) [/edit]

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

im mayb new 2 c++ but im not dumb.... any way thanx for all your help... i actually figured it all out... thanx to those that did help...

and another thing plz be more friendly... there are millions of forums out there.... i nearly decided to just leave this cause ppl are so unfriendly.... yes if i make a mistake, its fine by telling me where... but dont assume im an idiot... and say sh*t things

once again thanx

I was only going on what you said in the comments
>> // when i compile it says error is here

That points to the line that declares several string object. The only conclusion I can make, without seeing your entire program, is that you failed to include a header file. If you took my comment as a shitty thing then you should have included more information that I could use to evaluate your problem. I can't see your monitor and I can read your mind.

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

>> // when i compile it says error is here
I suspect you failed to include <string> header and/or failed to identify the namespace. But again I don't know because I can't see your monitor.

#include <string>
...
...
std::cout << fight[n].name << std::endl;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>only prob i have now is storing it in2 an class array

What array? You need to post the exact class declaration instead of making us guess what you are doing.

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

The first thing you have to do is design the structure. What information is on each line of the file? You can't do anything else until you figure that out.

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

srand() doesn't return a value. All that function does is seed the random number generator.

What you want is rand(), not srand(). srand() should be called only once at the beginning of the program to seed the generator. From then on the program calls rand() to get a random number.

#include <time.h>

int main()
{
   srand( time(0) );

   int n = rand();
}

Note that rand() returns an integer, not a float or double.

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

I tried it with both VC++ 2008 Express and Code::Blocks 8.02 on Vista Home Premium. No problems or errors. With both compilers I first created a project and compiled for debug.
This is what Code::Blocks console window

Hello world!

Process returned 0 (0x0) execution time : 0.040 s
Press any key to continue.

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

You need to pay attention to detail more closely.

>>for (j= 0; j > 2; j++)

use the < operator, not the > operator.

>>for (i= 0; i >= 5; i++)
Same problem as above -- use < operator, not the >= operator.

>> row = a[j];
>> col = a[j];

No, No, No. You want to set row and col to the values of the loop counters i and j.

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

To Ancient Dragon: I read about "lazy evaluation" in some book, but I don't remember which one :( ... Anyway, here is wiki on it.

OMG I've been doing that for 50 years and always thought it was called procrastination. Now I know I was just plain lazy :)

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

Wusses!

You were all to ready to exploit the cheap overseas labour so long as the economic pendulum was swinging in your direction.

Not so. We have been complaining about it for years. Its the Big Business who have been doing that, not the working class American citizens who lost their jobs over the past 20+ years. None of our Presidents over the past 20 years have had the balls to do anything about it.

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

To find both row and column, start the function out by setting both values to 0, and temp to the value of whatever is in a[0][0]. Then if the value in a[j] > temp (note: not >=) change the value of all three variables -- temp, row, and col.

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

Reading the information from the data file is very much similar to how you have it coded now to get it from the keyboard. The only difference is that you have to open an ifstream object.

ifstream in("infile.txt");
int i = 0;
while( in >> studentInfo[i][0] )
{
    in >> studentInfo[i][1];
    // blabla for all the other items

}

But why didn't you just use a structure to simplify things:

struct person
{
    std::string lastName;.
    std::string firstName;
    // blabla for all the other fields
};

Then you could have done this, which is a lot more meaningful than what you have done with simple arrays of strings.

struct Student studentInfo[20]; 
int i = 0;
ifstream in("infile.txt");
while( in >> studentInfo[i].lastName)
{
    in >> studentInfo[i].firstName;
    // blabla
}

And then, in C++ where are even easier ways to accomplish that, but you may not have studied c++ classes and vectors yet, so I'll not mention them any more.

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

I have no idea what you are talking about. What is "lazy evaluation" ? And why does it matter whether cio_putstr() returns void or something else ?

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

>>unsigned short int

If you are compiling for UNICODE you should be using wchar_t datatype for portability. *nix computers define wchar_t as unsigned long int, which is obviously not the same as MS-Windows. And the last time I read the UNICODE standard was considering a 64-bit integer so that it could hold more Chinese graphic characters.

I was also under the impression that VB passed BSTR strings to C/C++.

tux4life commented: Since when are VB applications portable to Unix? :P +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

We have a lot of ghosts here in St Louis -- they even vote every election year :)

Ezzaral commented: heh! +22
ahihihi... commented: Sumimasen.. NYAHAHA! +1
amrith92 commented: Ghost Voters: whatever next! :) +1
scru commented: haha +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Ancient Dragon is an idiot and doesn't know what he's talking about. .

Agreed -- had a Senior Moment :)

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

There is none. Here is an explanation.

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

why use LoadLibrary()? If you wrote the DLL then you should have *.lib which can be linked just like any other library and its functions called just like any other function.

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

We all know that Obama has made it clear that he is going to make restrictions on outsourcing businesses. If implemented then that means trouble for many countries that relies on outsource businesses like call centers and other businesses. Do you think it’s a sound decision made by him?

Yes, I agree with Obama on this issue 100%. Outsourcing needs to stop, American jobs need to stay in America not some other country.

Of course outsourcing might be ok if USA could tax them and require them to hire American employees. But I know that will never happen.

Will it hurt other countries? Myself, I could care less whether it does or not.

There is one solution to this: other countries outsource their jobs back to USA.

Sturm commented: Because freedom is bad! -1
jephthah commented: because sturm is an idiot +9
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

and it (I mean, including <string.h> ) does not produce any backward warnings at all...

why should the compiler produce warnings? string.h defines functions such as strcmp(), strcat(), etc. which are related to character arrays, not std::string. Those functions and that header file were inherited from C language.

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

Are you sure that this program compiles? You seem to have used string in your code, but you haven't included <string.h> at all...!

That's because std::string is not declared in <string.h> -- its in <string> header file. And some compiler include <string> with <fstream>

tux4life commented: Correct! +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't have that compiler, but browse through the project options and see if there is a flag to build 64-bit programs.

also browse these google links

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

compiling on a 64-bit operating system is not sufficient -- you have to build it with a 64-bit compiler.

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

Welcome to DaniWeb. Please feel free to browse around the many threads we have about networking and other topics.

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

That part of your program works fine. Now the problem is in the function displayAll () shown below. The value of Horses_num in the loop is 0, so the loop doesn't to anything. What is that variable supposed to be? The number of horses read from the file? If yes, then you need to set it before initialize_file() returns.

void displayAll (Horses temp_array[num_of_Horses]) {
     
     int i;
     printf("\n******DISPLAY ALL******");
     printf("\n");
     for(i=0; i<Horses_num; i++){
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>but i seem to be encountering some problems.
Do you mind explaining what problems? Do are we supposed to guess?

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

unplug the speakers ?

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

post code -- we can't see your monitor.

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

Please seee post #11 in this thread because its the same problem.

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

>>if (answer1 == 'Leave')

answer1 is just a single character and you are attempting to compare it, illegally by the way, to a string. You need to make answer1 a character array and use strcmp() to compare it to a string. Or you could make answer1 a std::string object, since this is c++. Note the double quotes around "Leave".

std::string answer1;

...
cout<<"You awake and get out of bed and realize that you want to go kill a dragon for no reason. Now what? ";
cin >> answer1;
if (answer1 == "Leave")
	right = 1;
else
	right = 0;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

THINKING

THAT MIGHT HELP....I'M NOT SURE....

Huh?? The code you posted as nothing to do with this thread. Maybe you meant to post in another thread?

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

lines 173-180 of the code you posted are wrong and incomplete. Here is one way to read the file:

int i = 0;
while( HorsesFile >> temp_array[i].hname >> temp_array[i].rname >>
    temp_array[i].IDNum >> temp_array[i].race >> temp_array[i].time)
{
         ++i;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

please post some of the actual contents of the file

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

what the hell! :-O Am I the only one who has absolutely no clue what he wants?

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

Why did you put all that C code inside a C++ program? I realize C++ supports FILE* and associated functions, but if you want to write c++ then do it the right way using fstreams and other c++ classes.

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

The link you gave is some sort of download page written in some language I don't know.

attach your project to your post here at DaniWeb. Just use WinZip to zip it up, press the Go Advance button in the "Quick Reply To Thread", then the "Manage Attachments" button.

This will not guarantee you will get the answer you want, but at least some people might bother to look at your project.

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

I think he needs to write a calculator program that uses reverse polish notation.

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

Where? ;)

Oops! link added.

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

Here is one way to do it , I think, without the complications of COM. The GUI interface is probably not what you want but you can extract the ideas that document presents.

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

All of the problems with the code you posted are due to carelessness -- misspelled words. When programming you have to learn to pay attention to small details, such as capitalization and spelling. Look at your compilers error messages and fix the problems one at a time. Normally the first error message is the most important. Fix it then recompile to see what's left.

Here is the program with all those errors corrected. I didn't run the program so I don't know if it works correctly or not.

// This program determines the commission on real estate sales
// depending on the type of property sold.

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

int main ()
{
  const double       RESIDENTIAL_RATE = 0.060;
  const double       MULTIDWELLING_RATE = 0.050;
  const double         COMMERCIAL_RATE = 0.045;

int          property_code;
double    sale_price,
             commission_rate,
             commission;

cout << setprecision (2)
       << setiosflags (ios::fixed)
       << setiosflags (ios::showpoint) ;
cout << "Enter the property's selling price: ";
cin >> sale_price;

cout << endl ;
cout << "Enter the property code according to the following."
       << endl << endl ;
cout << "Residental,            enter R" << endl;
cout << "Multiple Dwelling,   enter M" << endl;
cout << "Commercial,                enter C" << endl << endl;
cout << "Please make your selection:  :";

cin. get () ;                 // Discard the \n
property_code = cin.get () ;

    if( property_code == 'R' || property_code == 'r')
    {
       commission_rate = RESIDENTIAL_RATE;
    }
    else if( property_code == 'M' || property_code == 'm')
    { …
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I didn't attempt to compile it, so you may be right about that. There are a lot of other problems with that code, but fixing them was not the object of this thread.

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

This didn't compile without problems for me.

Remove all those comments at the top, then it will compile -- at least it did with vc++ 2008 express. I don't have time this morning to debug the code. My suggestion to the OP is learn to use your compiler's debugger and find out why the program fails to work correctly. That's what you will have to do if you ever get a professional job coding.

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

>>could you please tell me how to use it in detail?
How to use it for what? If you want to just know about ifstream, then just google for it.

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

In that case its not a pointer problem because you removed all pointers. So I have no clue what's wrong.