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

Q2: Yes -- there are lots of places that look like memory leeks --
line 24: where is that object deleted?
lines 13, 20, and 63: does parse() return a char pointer that needs to be deleted? If it does, then these lines are memory leeks too.

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

Oh! Well, read the docs for fopen() function, it has an argument that will cause fopen() to create the file if it does not exist. Here is one of several links to the man pages for that function. Since fopen() is a standard C function it will work the same on most operating systems and compilers.

Here are some other useful links.

and save a struct in archive

The easiest way to save a structure in a file is to create the structure with a word processing program such as Notepad.exe. Probably all compiler IDEs will also let you save them to a file.

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

you might try typecasting, like this:

transf = transformaclave( (const char*)c);

[edit]Sorry, I didn't see other posts before I posted this. Just ignore me since the problem is already solved.[/edit]

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

Thanks, turning off DaniWeb tooltips fixed the problem.

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

what compiler are you using? I just compiled with VC++ 2005 Express and got no such error message, although I did get several others because you tried to make the return value of sizeof operator negative. Just typecase sizeof to return int and that corrects that problem.

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

I'm seeing two tooltip windows for the same thread. See thumbnail. The grey one on top disappears after a few seconds.

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

If you are using MS-DOS or MS-Windows and writing a text program (not a windows program) then the output goes to the command prompt window just like it does in all other text programs. If you are writing a windows program then the text output will go into the bit bucket never to be seen again.

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

If you are talking about MS-DOS or the MS-Windows command prompt window, there is no other way to do it. You will have to use graphics mode to display different fonts, and in assembly that would be a huge task.

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

Include directives always, always go at the top of *.c and *.cpp files, you will often also see them in *.h files. If the program consists of more than one *.cpp or *.c file then the include directive should appear at the top of each file in which the object referenced in the include file will appear. Example: you have main.cpp and CATCenterNetClient.cpp, but only CATCenterNetClient.cpp will reference something in CATCenterNetClient.h then only put CATCenterNetClient.h. at the top of CATCenterNetClient.cpp. If both main.cpp and CATCenterNetClient.cpp reference something in CATCenterNetClient.h then add the include directive at the top of both main.cpp and CATCenterNetClient.cpp.

This matters only to inform the compiler about the classes and definitions used in the *.cpp files. It doesn't really matter if you include CATCenterNetClient.h in *.cpp files that do not use it, all it does is make compile time a little longer. The compiler will ignore CATCenterNetClient.h if it is not referenced in the a *.cpp file.

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

You can't invoke one executable program (*.exe) from another by merly including a header file and calling new to create an instance of it. You have to use CreateProcess(), ShellExecute() or another similar function to launch an instance of that program.

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

my problem for introducing hetrosexual is to calculate the people above 32, so how can i do that if hetrosexual is ignored

Because you will be excluding everyone over 32 who are homosexual. Sexual orientation is not the same as genderless. Learner's response is a reasonable solution.

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

how to create an archive depends on the compiler you are using. *nix compilers normally use the ar program.

structures are not put into archives, which contains only compiled object code. Put the structure in a header file that can be easily accessed by any *.cpp or *.c file that you want to use it in.

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

>>where do I write the include commands for these header files

Not sure what you mean by that. Do you mean #include <myheader.h> ?

>> instantiate the headers
Headers are not instantiated. Only objects and POD (Plain-Old-Data) are. So again, I don't know exactly what you are saying.

Maybe post an example of what you want to do will help clarify your problem.

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

I agree with this poster.
Suggesting multi-threading to a beginner programmer is like giving a gun to a 3 year old. And since we're talking C++ here you can be damn sure he'd reuse the bullets!

What needs to be conveyed to the original poster is what design patterns can be used to achieve the desired effect.

Don't shoot the messenger! Brent asked about multi-threading, so I pointed him in that direction. I won't pretend to know his skills or read his mind.

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

>> need to learn how to multitask in c++.

Its called multi-threading. Here are more information.

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

If gener does not matter why not just leave the gender undefined instead of introducing sexual orientation of hetrosexual or homosexual into it. Likewise with the other categories. If for example age does not matter then you would not want to classify someone as either "ancient" or "youngster".

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

I have never needed a gun to defend myself either, but people in large cities where criminals/drug dealers live do need them. I don't even own a gun, but I don't object to others owning and carrying them.

I hope non-Americans have the idea that all Americans carry a pistal on the hips and have shoot-outs in the streets like they do in old western movies. We may be nuts, but we aren't crazy. Hollywood gives Americans a bad reputation for that, and makes non-Americans think that all we do all day is shoot at each other.

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

line 12 is still incorrect. The initial value of the loop counter i is initialized to 1, so the exit condition i >= 100 will immeditely fail and the loop will stop. what you want is something like this:

for(i = 0; i < 100; i++)

In this case the loop counter starts at 0 and continues the loop until it reaches 100

Before you can calculate the values you have to add some code to either get the values from the keyboard (bad idea because there are too many ) or read them from a file (most appropriate source of the data). If you get the data from a file, lines 31 thru 35 are not necessary and can be deleted. Likewise you do not need lines 52 to 55. It is not necessary to ask questions when reading the data from a text file.

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

This is one of the reasons I'm not certain that calling the National Guard a militia is valid; the militia was supposed to be for the protection of the state against the federal government; the National Guard, as I understand it, is a part of the federal military structure. This leaves us with a conflict of interest.

Not just our own federal government but proect us from foreign invadors too. I don't see our federal government being any sort of threat any more, so being a conflist of interest of not anything to be concerned about. But I do think using the National Guard to supplement our federal military troops to fight wars in foreign land is wrong. It might be leval, but its wrong.

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

since when did you think that removing guns out of the hands of law abiding people will make the world a safer place? What did people use to kill other people before the gun was invented? Are we also to ban knives, bows & arrows, and rocks? Remember, it was the Chinese who invented gun power, not Americans. And it was in 1718 in London that the pickel gun was invented.

And how about this story of the little old 81-year-old lady who shot off the testicals of a rapist. There have been a lot of similar stores where guns prevent crime. So you think she should have called the police?? The police are not our personal body guards -- its our own jobs to protect ourselves.

EnderX commented: Nicely put, and interesting link. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Homework ?

you might also research some of these google links.

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

you should probably wait on classes until you study them in school.

simple integers will work too if you are more comfortable with using them and it appears you have already defined them. Each of the variables should be initialized to 0, not 1 or 2.

If the data is coming in from a data file then you need to declare an ifstream object and include <fstream> header file. After opening the file read it until no more data (end-of-file). Since I don't know the file format I can't really give any more detailed instructions. Can you post the first two or three lines of the file?

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

Where is the data coming from? I hope its from a text file because entering all those questions for 100 people from the keyboard would be a real pain in the a** :)

If you know about c++ classes yet then that would be the most efficient way to write the program. Otherwise just simple arrays will do.

>>i can assure u sir this program is giving me sleepless nights

Yea, programming has that affect on all of us. :twisted:

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

so can you help me?

The problem is in the makefile. Since you didn't post it nobody here is going to be able to help you.

maybe that makefile was not written for your compiler? You have to read its docs from whereever you got it.

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

>>some causes of segmentation fault
Just a few:

(1) attempt to execute a program that does not compile correctly. Most compilers nowdays do not produce the executable when there are compile errors, but I have seen a few compilers do that in the past.

(2) buffer overruns

(3) using uninitialized pointers

(4) dereference NULL pointers

(5) attempt to address memory the program does now own.

(6) failure to check for data validity before using it.

(7) faileure to check for file open success before attempting to use the file pointer.

>>my main prob.. is i can't completely compile my program..
ahmm.. it can't find my database..

Those are two unrelated questions. Please post code that will not compile and post the error messages.

What kind of database are you using? What compiler? What operating system? Is the database in the location you told your program that it is in?

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

Please, the next time you post code please please copy so that it retains spacing. How to do that will depend on what compiler you are using

The loop at line 15 is constructed incorrectly. The for statement contains three parts -- (1) initial value of the loop counter, (2) test to determine when to exit the loop, and (3) increment or decrement the loop counter.

The statement on line 15 skipped the first part (initialize loop counter)

Example to correct that line:

for (i = 0; i<100; i++)

Now the problem is: what is line 15 supposed to do? What is really does is execute line 16 100 times -- or set highestgrade10 to a constant value 100 times. You can achieve the same thing by deleting line 15 (the loop) so that line 16 is executed only one time.

If your intent is to execute more than just line 16 within that loop then you need to add braces '{' and '}' around the lines that you want executed, like this

for (i = 0; i<100; i++)
{
      // code to be executed go here
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The only reason to monitor rep comments is to filter out objectional language and the language filter should do that. Otherwise I could care less about the comments, other than to read them and possibly find out any problems I may have caused.

Serunson commented: thanks for the rep! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you can put it anywhere you want -- there is no restriction. Just add the -L flag or specify the whole path in the .o filename.

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

Does anyone else think that prisoners on death row deserve their last meal rights?.

Yes, but only because it is a traditional thing to do. It does seem sort of silly to give a person something to eat just before we kill him, but hey, its a feel good effort to make us feel good about ourselves for killing another human being.

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

I think it's supposed to be white collar crime :)

you are correct -- sorry every for the apparent racist remark which was not intended.:$

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

>>you can call the function at any point of the program
that may, or may not be recursion. recursion happens only when the function is called somewhere within the same function. For example

void foo()
{
<snip>
    foo();
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>for(j=1;j<=1;j++)
It will never loop more than 1 time therefore you might as well delete that line. There is no point in writing a loop that only loops one time.

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

do it all on one line

IPHeader_format IPHeader1 = {1 , 4 , 5 , 0 , 1500 , 1 , 0 , 0 , 8 , 4 , 0 , 0 , 65535};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I don't see anything wrong with it. Maybe its just your eyes, or maybe they fixed it.

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

I'm sorry I didn't see your question before now. If you are still having a problem with this please post your most recent attempt to solve it.

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

Sorry, we do not do people's homework for them. You need to post the code that you wrote, post error messages your compiler yelled at you, and ask questions.

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

use a stucture, like this

struct num
{
    unsigned short v1: 4;
};

int main()
{
    num var;
    var.v1 = 5;
    printf("%d\n", var.v1);       
    return 0;

}
Aia commented: Very clear +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you don't compile header files, only *.cpp and *.c files. you can list all the *.cpp files on the same line if you want or compile and link them separately.

Doing this from the command line is messy, but feasable. You have to learn all the switches -- there are a lot of them, but you don't have to know them all at once.

you can also create a makefile which contains all the compiler and linker commands. makefiles can get somewhat complex and you can find more about them by using google or searching microsoft.com.

The easiest way to do all that is using the compiler's IDE, which will correctly compile and/or generate the makefiles for you.

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

>>this is the code i use but an error occur
what is (are) the error(s) ?

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

Short answer: learn them all.

Note: Forget about VC++ 6.0 -- its ancient and rarely used except for maintenance of old programs.

Visual Studio 2005 Professional
Visual Studio .NET 2005 Professional (or 2003 Pro)
Visual Basic 2005 Express Edition

These are all variations of the same compiler. also don't bother learning 2003.

>>I have a *bit* of classroom experience with C and C++, but didn't feel at a comfortable level with it even before forgetting it all
If you don't like either C or C++ and are unwilling to learn them then you can scratch off all the compilers (such as those quoted above) from your list.

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

maybe you should contact BumbleBee. Also possible that VC++ 6.0 is too old. You might try a more current compiler such as the free VC++ 2005 Express.

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

put them all in the same directory as main.cpp. The compiler default is to put them in the current working directory. You can confirm that yourself by compiling a program then listing out the files in that directory.

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

In addition to the two choices I posted previously you could use the stars

void foo(int **array)
{

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

I don't see any difference. But I did get 1,340,000 hits on SERPS :sweat:

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

Write a Macro instead of function like this.
#define sizeof(x) ((char *)((&x)+1) - (char *)&x)
It should work .

That macro doesn't work either for the same reason Narue and I explained.

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

All arrays, including multi-deminensional arrays, are passed by address, never by value. Passing a 2d array is similar to 1d array, the sedond deiminsion is optional.

void foo(int array[10][10])
{
  // blabla
}

or

void foo(int array[10][])
{
  // blabla
}

int main()
{
   int array[10][10];
   // now pass the array to the function
   foo( array );
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you could use either a do-loop or while-loop. For example

start of loop
    display menu
    get input 
    is input one of the menu items?
    yes, when exit the loop
 end of loop
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

line 140 -- replace the dot with a space to declare an object.

iamthwee commented: Was there any point of adding code tags? -2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

[sarcasm]We could close all our prisons if we just gave everyone immediate death sentence -- to be carried out about 10 minutes after sentencing. Got a speeding ticket? death sentence. petty theft? death sentence. white color crime ? death sentence. We would not need any jails, prison wardens or prison guards because nobody would be sent to prison.[/sarcasm]

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

We in Illinois have been using 10% ethanol for quite a few years now (20 years that I know of) and it has not helped lower the price of gas one penny. I heard it might actually increase the price at the pumps because it costs more to process ethanol then normal gas.