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

Just a thought, but this may help you

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

Delete line 19 because the prototype on that line is probably not the same as the prototype found in string.h. Why prototype something twice ?

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

The base class is where you would put pure virtual functions so that all derived classes have to implement them. Although the boat class may not have doors, then getNoOfDoors() would just return 0 so that the virtual function would be implemented in the derived class.

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

>>please solve this question for me now..
No. Do it yourself.

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

Hello i want to retrive information of various fonts used in an RTF file.so that i can use it in my RichEditCtrl class.

That's nice. And I want a million dollars.

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

What did you mean by 'he's a hack'?

The instructor is an idot who has no clue how to produce modern C or C++ programs with modern compilers. He probably learned how to teach on an old 20-year-old computer and MS-DOS 3.1 with Turbo C, which was one of the best at that time.

Universities should be teaching students the art of modern computer programming with modern compilers and modern operating systems. What is that instructor doing?? Answer: He is teaching students how to use 25-year old technology that no one in industry uses today. And that is really unfortunate for the students because it means they will have to teach themselves what the university should have, but failed, to teach them. How in the hell can someone from that university get a job writing programs for modern software houses?

Salem commented: Well said - students are being robbed by being taught fossil-ware +19
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

where did you call popen() to open the pipe?

[edit]Oh never mind. I checked the *nix man page and it appears you did it the same way as in the example. Since I don't use *nix very often I have no clue what is wrong. [/edit]

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

I'm not in the mood for playing guessing games today, so I'll pass on this one.

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

what operating system, what gui, what compiler ??? We need a whole lot more information that what you have provided.

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

I wish Dani would write a bot that would automatically delete any post that even mentions Turbo C or Turbo C++.

jonsca commented: If only I could give you more rep than this, I would. :) Check out the post in Area 51. We were going to try to throw a sticky together for it. +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

And thanks for wasting all my time and others too here at DaniWeb. I see you also posted the same at dream.in.code.

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

No. All is does is read the file. Where do you see use of cout in that code, e.g. cout << Car_array[i].make; ???

And delete lines 6 and 7 that you posted. After reading the file you don't want to re-initialize the class because the init() method will destroy all the information that was read from the file.

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

Well, if you look at the last few lines in main() you will see that all it does is read from the file. You have to add more code to display the information. Create a short loop and display the value of each of the Cars.

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

Does one thread depends on the results of the other thread? Or main() needs the results of the other two threads() ? Maybe you need to add a WaitForMultipleObjects() -- or something like that -- in main(). Without more detail its hard telling what is going on.

To answer your specific question: I don't know how to do it, but I think it can be done because there are several programs out there that I think do it.

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

When I add that to the car class I get this error:

1>carclass.h(132): error C2355: 'this' : can only be referenced inside non-static member functions

You did not make it an inline function -- in the implementation code you have to do like all other class methods

void Car::init()
{
  // blabla
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

C, C++ and C# are all very similar languages, but also very different. Most of the concepts in C were used to create C++, and likewise most of the concepts of C++ were used to create C#. I agree with Myrtle that it may be better to lean one of the two languages first before diving into the other. But each person is different and learns in different ways. If you can learn both at the same time without confusing them then more power to you.

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

Oops! I'm sorry for that. I added that to the Car class so that I could verify the program was working. Just delete that loop and line. But if you really want to keep it, here it is

void init()
    {
        memset(this, 0, sizeof(*this));
    }

Note that initializing a class like that may not always work correctly, and in many cases might actually destroy important data. Use this syntax very sparingly. As a general rule of thumb it is better to initialize each member object individually.

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

No one knows everything about everything. IMO you will know you are a good programmer when your peers tell you that you are one. And that takes a lot of time and practice. Employers do not expect entry-level people to know a lot about programming. You should be able to write simple programs, and probably make errors while doing it. You will not be expected to have the knowledge of someone with a Ph.D. or 10 year's experience. So don't be so hard on yourself. I had a prof who told the class once that graduating from college is not the end of your learning experience, but only the beginning. College just gives you the tools to learn.

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

The only thing I find annoying is, when editing a post, having to use the mouse to move the focus to the "reason for editing" box. In previous versions of DaniWeb the tab key sent the focus to that box. I would think its just a simple matter of changing the tab order to change it back to the way it was in previous versions. BTW PFO works like this too and would like to see it changed there too.

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

I think what is even more strange is that Walmart sells dirty jeans with holes. That is why I avoid places like Walmart when I need to shop for something.

WalMart is not the only store to do that. Dirty jeans with holes are very popular in USA, and stupid people pay lots of money for them :)

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

Sorry that I have not been involved in this discussion all day as I have been at work.

The first problem I see is that you don't need that struct record at all. All you need to read and write are the array of Car classes. The code you originally posted can easily be adapted to do that.

Car carsArray[3];

// to write them to a binary file, just do this
ofstream out("dats.dat", ios::binary);
if( out.is_open() )
{
    out.write( (char *)carsArray, sizeof(carsArray));
}

// to read the array is almost the same as writing them
// the only difference is use read() instead of write()

ifstream in("dats.dat", ios::binary);
if( in.is_open() )
{
    in.read( (char *)carsArray, sizeof(carsArray));
}

That's all there is to it.

Your original post almost had it right. Just delete the structure. Note that your original program may not have worked because you failed to close the output file before opening the input file, so the operating system had not flushed the data to the disk before your program tried to read it.

int main () {



	const int SIZE = 3;
    size_t x;			
	//Array of 9 cars
	Car Car_array[SIZE] = { Car("Porsche", "911", "Silver", 2005, 18990), 
							Car("Ford", "Mustang", "Red", 2007, 49842),
							Car("Chevrolet", "Beretta", "Black", 1989, 90332)};


      ofstream out("binaryFile.bin", ios::binary);
      // write three cars
      x = sizeof(Car_array);
	  out.write( (char*)Car_array, x);
      out.close();
      // read 3 cars
      for(int i = 0; i < 3; i++)
          Car_array[i].init();
      ifstream in("binaryFile.bin", ios::binary);
	  in.read( (char*)Car_array, sizeof(Car_array));
      in.close();
  return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I work as cashier at WalMart and something I sell quite often is dirty jeans with the knees ripped out or holes in other places. Strange that some one would spend good $$$ for dirty torn jeans :) :)

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

If this is a Linux/Unix program then you have to compile with -lcurses

gcc filename.c -o filename -lcurses

Why? getchar() is defined in stdio.h not curses.h. Oh wait a minute -- you were talking bout getch() which might be in curses. I don't think that's the one the op was talking about. He was referring to the one in conio.h which is a compiler-specific header file and AFAIK is not supported under *nix.

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

Then you will not have to open that file as binary. If the file looks like this: 0x01 0x02 0x03 0x04 OR maybe even like this: 1B 1C 1D 1E 1F (numbers separated by white space) Then you read it like this:

ifstream in("something.txt");
int a, b, c, d;
in >> hex >> a >> b >> c >> d;

On the otherhand, if the file contains the binary value of an integer, then read it like this (assuming sizeof(long) = 4 on your computer and compiler)

long x;
ifstream in("something.txt", ios::binary);
in.read( (char*)&x, sizeof(long));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
//Sets to default values
Car::Car() {
	make = " ";
    model = " ";
    color = " ";
    year = 0;
    mileage = 0;
}

What will I set the char's make, model, and color = to??

The constructor isn't quite right. To make an empty string all you have to do is set the first byte to 0.

Car::Car() {
    make[0] = '\0';
    model[0] = '\0';
    color[0] = '\0';
    year = 0;
    mileage = 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Probably not. I suppose you could keep it encrypted, but even that will not prevent some smart hacker from decrypting the password. There really is no bullet-proof way to save passwords, anywhere except in the human mind.

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

I don't wear clothes, I go naked :)

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

It depends on the contents of the file -- every binary file is different. In a nutshell, use ifstream's read() method.

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

That sounds like the classic circular array. The way I did it was to have two counters. The first counter indicates the maximum number of strings that can be put into the array (e.g. the array's allocated amount). The second counter indicates the next insertion position int nextpos; When nextpos == max then its time to wrap nextpos back to 0.

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

I don't know about you but I like to wear cloths.

You mean thongs??

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

I don't like jeans -- never had them on my body since adulthood (wore them on the farm when I was a kid). Also don't have any tattoos.

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

@Dave: what are you rambling on about??? What does INT_MAX have to do with subtracting two character values?

>>You are the lord of this roost. I
Not because I am any smarter than anyone else -- I just liked to post and answer questions a lot. I never said I knew everything -- indeed I've screwed up lots of times.

>>especially since you always come along and tell people to write implementation-specific stuff

Not knowingly. If *s1 - *s2 is implementation specific then please tell us why instead of pussyfooting around it. If there is a case where that does not work, then please tell me because I'm all ears :)

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

>> #include <stdio.h>

Delete that line. This is c++ program, not C.

When posting code put it in code tags [code] // your code goes here [/code] so that we can read it.

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

use it just like you would any POD (Plain Old Data). Your question is so vague that all I can give you is a vague response.

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

>>unsigned char byte2[1]="0X";
Wrong. You tried to stuff two characters in an array that can only hold one. Something like me trying to stuff my gut into pants that are too small.

You didn't say whether you are allowed to use standard C functions or not. If you are, then use strcat() -- look it up if you don't know how to use it.

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

Your options are NOT either Dev-C++ or BUY a commercial compiler. There are several very good free compilers. Both Code::Blocks and VC++ 2008 Express are free. Dev-C++ is no longer recommended because it's pretty much dead and is installed with an old version of the MinGW compiler.

If you are just starting to learn programming then spending your money on a commercial compiler is a waste of your $$$. If you have that much $$ to throw around then you can throw some in my PayPal account :)

Nick Evan commented: Good advice, but I also have paypal :) +12
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I think I know the thread now -- and I agree with you that it should have been split from the original thread. Oh well.

jephthah commented: e tu? +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

call modf() to split the double into integer and fractional parts. Microsoft (as well as others) compilers have a lot of floating point functions that come in handy from time-to-time.

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

I can't run the compiler if it isn't installed first. All I have are the cab files you see in the picture I posted.

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

I can't install it

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

Huh??

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

and remember that waiter is serving 4 more tables at the same time (roughly) so he's getting not $60 an hour (tax free...) on top of his wages, but $300.

In US tips are taxible just like other wages. And the $60/hour assumes the waiter serves 4 tables in an hour and gets $15 from each table. Of course the waiter does not get to keep all that money himself -- AFAIK it is normally split with the busboys, cooks, etc.

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

Hi :)

At this time, we're only accepting tutorials that are unique content to DaniWeb, and not reproduced elsewhere on the web.

And the result is that there is only ONE tutorial in the c++ forum. Is the reason that no one has submitted any tutorials, or is it that you and Davy have not approved any more of them ?

I would think you would get more tutorials if you allowed people to post them in a tutorial forum that requires mod approval for permanent post. Sort of like the way its done on PFO and other web sites. As it is right now, no one knows how to post them, so you don't get any at all.

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

Perhaps we are using a word compiler too liberally. As I said above, and you just confirmed, the conversion happens in one of the crt*.o files. These files are added by the linker. In a strict sense the compiler compiles a translation unit it into an object form - and may not (doesn't have a right to) change any observable logic. A return 0 compiles into return 0.

And how do you think that crt0.o file got generated? It was either with the compiler or an assembler, maybe a combination of the two.

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

People just continue to use 0 rather than EXIT_SUCCESS because it is rather easier to type.

Old timers like me use 0 out of habit. I started programming before c++ was invented, and even before there was such a thing as function prototype. Magic numbers were the norm in those days -- and old habits are hard to break.

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

You can't even install TC on MS-Windows version Vista or Win7. I tried it and it doesn't work. IMHO TurboC/C++ is a great compiler for hobbyists and teenagers or pre-teens. But in order to use it you must have an old version of MS-Windows or MS-DOS installed. Professional programmers wouldn't even think of using that compiler.

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

@Dave: how can *s1 - *s2 cause an integer overflow? The maximum values would be -255 (0 - 255). That's hardly even close to an integer overflow value.

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

The user enters a name and then decides he/she wants to display the name via the saved list, but once they enter the name, they cant display the entered name in the saved list straight away ...

The solution is to save the new name in the list as soon as the user enters it. Why wait until the program is closed to save the list?

To delete a name you have to rewrite the entire file, omitting the name you want deleted.

What's all that about user #1 and user #2?? Are you running the program on a network which is accessed by multiple computers?

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

what compiler do you have? If you have Dev-C++ then you will have to download the windows package using the Dev-C++ IDE package manager. I think there is a menu item for that.