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

>>Nor, is my C++ for Dummies

That book is a waste of good money. If you want to know what books to buy than read this thread.

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

Here's one that was written by Altert Einstein. Can you solve it? (Hint: create a matrix on paper to keep track of who does what)

There are 5 houses in 5 different colours. In each house lives a person of a different nationality. The 5 owners drink a certain type of beverage, smoke a certain brand of cigar, and keep a certain pet. Using the clues below can you determine who owns the fish?

* The Brit lives in the red house.
* The Swede keeps dogs as pets.
* The Dane drinks tea.
* The green house is on the immediate left of the white house.
* The green house owner drinks coffee.
* The person who smokes Pall Mall rears birds.
* The owner of the yellow house smokes Dunhill.
* The man living in the house right in the middle drinks milk.
* The Norwegian lives in the first house.
* The man who smokes Blend lives next door to the one who keeps cats.
* The man who keeps horses lives next door to the man sho smokes Dunhill.
* The owner who smokes Blue Master drinks beer.
* The German smokes Prince.
* The Norwegian lives next to the blue house.
* The man who smokes Blend has a neighbor who drinks water.

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

is that same as condition ?! like if records.m_f == 0 print male else print female ?!

yes.

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

When I compiled your code I got a warning in function main() that variable STU was being used before it is initialized. You need to make certain you fix all warnings as well as errors because most of the time warnings such as this one are actually errors.

fgets(STU->FName,sizeof(STU->FName),stdin);

The above is the offending line. STU has not been initialized to point to anything.

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

Here is another example

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

Here is one example of how that's done.

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

quite frankly I don't think there are a whole lot of programs out there in the commercial world that use win32 api console functions very extensively -- most programs have GUI front ends. But here is a link to some example programs.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
printf("%s",records[i].M_F == 0 ? "Male" : "Female")
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

arrays are always passed by reference, never by value. Both andor's example and mine pass the array by reference. The only difference between the two examples is in the function foo() -- In Andor's example the parameter is declared as a pointer and in mine it is not.

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

yes, I think it would be challenging for college students. You can simulate some of this by using a laptop or other computer to simulate the scanner (have it transmit barcode data to main computer every 1/2 second) and another computer or laptop to simulate a printer.

>>Is there already some production line standard like 1 second
the standard is 1/2 second, and management would like to make it faster than that!

There is actually more to the program than I revealed. For example, there is a switching center further down the production line that moves the boxes to different trucks for shipping to customers. The program also has a list of customers, the trucks and how many of each type candy do to each customer. The program will also have to send data to the switching center to tell it what box goes on what truck (robotics!). This production schedule is reset at the start of each shift (3 shifts/day, 24 hours a day, 7 days a week).

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

>>so let me know if it's even doable

Absolutely and most definitely YES. We do it all the time. just pass the name of the array. Here is a simple example.

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

int main()
{
   int array[10];

   foo(array);
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

all c strings are terminated by 0. strlen() only returns the number of characters in the string so you have to add 1 more for the null terminator. If you don't very nasty things tend to happen to programs (been there, done that!)

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

>>param[parateller] = malloc(sizeof(midl));

The above is also wasteful -- should allocate the length of the string + 1

param[parateller] = malloc(strlen(midl)+1);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are lots of tutorials -- here is just one of them

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

If I understand you right, you want to split the sentence "Hello World" into an array of two strings -- "Hello" and "World". Assuming variable midl is just a temporary buffer to hold the current word, you do NOT want to use strcat() to copy the ith character into it.

int n = 0;
		for(i=0; i < (strlen(text)); i++){

			printf("Midl: %s\n", midl);

			midl[n++] = text[i];

			if( isspace(text[i]) ){
                                      midl[n] = 0; // null-terminate the string

				param[parateller] = malloc(sizeof(midl));

				strcpy(param[parateller], midl); 

				printf("Parateller: %d\n", parateller);
                                      n = 0;
				parateller++;


			}

That should handle the words before end-of-string is found, but not the last word. You need another check after that loop terminates so that you pick up the last word in the line.

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

What is causing this, and how do I avoid it?

This line is causing it

strcat((char *)&midl, &text[i]);

how to avoid it? I can't say because I don't know what you intend for it to do.

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

Turbo C??? I thought that was pretty bad 20 years ago!

At one time it was one of the best MS-DOS compilers on the market -- Microsoft compilers really sucked cannel water in those days and NOBODY used their IDE. That was when Lattice C was king of the hill.

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

sort the vector first, then you can use a binary search algorithm

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

ios646.h is apparently available in the C99 C standards. But I don't know how many compilers have implement those new C standards yet.

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

not possible unless you already have a pointer to it because your program does not know the address of the node and because you also have to remove it from the linked list before deleting it.

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

sounds like you got some very very old and ancient MS-DOS code, such as this program. To make effective use of the REGS union you need to learn some assembly language, and especially about software interrupts 16 and 21.

Those are not useful with any of the moders 32-bit compilers. If you are using MS-Windows then you should learn the win32 api console functions.

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

I don't know how much equipment (hardware) you have at your disposal, but one real-world example is:

Lets say we are in a factory that manufactures several different kinds of candy. After the candy is put in shipping containers (corrugated boxes) they roll down an assembly line past a barcode printer which prints a barcode that describes what is in the box (product code). At this point each kind of candy has its own conveyer belt so that all the boxes on a conveyer belt are the same thing. After that, the boxes flow into a single line, which might look like a Y shape. The boxes travel along the line past a barcode reader, at the rate of 1 box every 1/2 second, which reads the barcode and transmits it to a PC running your computer program. The computer program listens on the serial port for input from the barcode reader, when the data arrives the program uses the barcode data (I2OF5 format) and looks up a record in the database. After reading the database information, it formats the data and transmits it via another serial port or USB port to a printer that will print information on the sides of the box (like this one for example).

Your computer program must do all that in less than 1/2 second in order to keep up with the production line speed. The information to be printed on the box (which is in the database) is the …

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

took me all of about 2 seconds to find them

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

that link crashed my computer. I had to turn the computer off,

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

You didn't tell this initially. We all thought that the cheat could steal only from his trinket. So the total was always 1 gram less than 55 oz. :eek:

The thief steals 1 gr of gold from each trinket he makes so the total is (1 * thief number) gr less than 55 oz.

One day the king learns that one of his slaves is stealing some of the gold and his trinkets weigh something less than 1 oz.

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

One thing is certain, end-of-the-world will certainly cause a crash in the real estate market, so will nuclear war. And prices in New Orleans (USA) plummeted after last year's hurricanes.

That's the situation as it was at the end of the .com boom when many people in IT lost their jobs and their houses and migrations started to areas where there still were jobs available.

That's one reason I am happy that I live in the mid-west -- we didn't feel the affects of that, IT jobs here are still pretty good. The wages are not as high as the west coast, but neither are the cost-of-living so it doesn't really matter that I don't make a million dollars an hour.

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

Ok, here is the answer: put 1 trinket from the first slave on the scale, 2 from the second slave, 3 from the third, ... and 10 from the 10th slave. If no one was stealing gold the trinkets will weigh exactly 55 oz (or 1559.22 grams ). But since the thief was taking 1 gr from each trinket they will weigh 1 gr times the thief number less than 55. If the thief was the 1st slave, then the pile of trinkets will weigh 1558.22 grams. If the thief was the second slave, then the pile will weigh 1557.22 grams ... and if he were the 10th slave the pile will weigh 1549.22 grams.

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

There's really no need to be horrid. :confused:

apparently there is since you have the nurve to beg everyone to do your work for you. Please read the forum rules posted at the top of this board.

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

>>I think I just need to see how to call it in the main function
looks ok to me, but I didn't attempt to compile your program.

double getData(int diamter, int price)

Above function needs similar conversion to use references.

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

If the text contains more than one sentence, first locate the end of the first sentence by locating the normal end-of-sentence terminators (period, question mark, exclamation mark). Then the first word following that is the start of the next sentence.

strpbrk() function will help locate the end-of-sentence.

char *end_of_sentence = strchr(textline, ".?!");
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

COleDateTime() does not handle milliseconds. If you add milliseconds to the DATE object you will invalidate the COleDateObject -- at least that was my experience with it. I had to subclass the COleDateTime class and handle the milliseconds myself.

And why would you want to add 10,000 milliseconds ?

The DATE type is implemented using an 8-byte floating-point number. Days are represented by whole number increments starting with 30 December 1899, midnight as time zero. Hour values are expressed as the absolute value of the fractional part of the number

The value to the right of the decimal point represents the fraction of the hour minutes and seconds, note that milliseconds are not included. For example:

30 December 1899, midnight  = 0.00 
4 January 1900, 6 A.M.  = 5.25 (5 days past 30 Dec 1899)
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Here are just a few helpful hints: They are not all inclusive and you will no doubt encount other problems during the porting process.

1. rename the *.cpp files to *.c files
2. convert the classes in the .h files to normal structures and make the class methods just standard C functions, passing an instance of the structure to the function.

3. delete the class constructors and destructors. They are not relevant to C language.
4. replace functions such as void account::deposit (const double &amount) to standard c functions, such the following, adding an instance of the structure as the first parameter. objects passed by reference have to be passed as pointers, not c++ references.

void deposit (struct account * acct, const double*amount)
{
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

the parameters of getData() need to be passed by reference so that getData() can change their values. So you make the function like this

double getData(int & length, int & width, int & price)
{

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

use tolower() instead of toupper() in that loop, then just use touper() on the first letter of the first word.

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

when declaring a function you must specify the parameter types as well as name. For example

double computeUnitCost(int length,int width,int price)
{
   // the code goes here
}

It is also necessary to declare the functions before they are used, so you need to put the function prototypes at the top of the program. Just simply copy the function declaraction shown above and paste it near the top of the program then terminate that line with a semicolon.

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

read this article, and this one about DATE data type

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

first you will have to learn assembly language of the machine that the code is running on. If you know that, then it should not be difficult to write the disassembler. I don't know about *nix, but MS-Windows every executable program starts with a header structure (Microsoft Portable Executable and Common Object File Format Specification) and that structure has changed slightly from one version of MS-Windows to another. Here would be the first place to start your research.

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

I was wondering what "ally C" is? anything like an "ally cat" ?:)

BTW: I have no idea about how to write a disassembler -- although I know an executable can not be disassembled back to C or C++ code. About the best you can accomplish is to generate the assembly language.

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

I guess I'm fortunant because I'm 63 and still have a full-time well-paying job. I have to wait until I'm 66 before I can collect full SS and I've thought about what to do if I do lose my job before then. Well, now I know.:mrgreen:

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

I compiled and ran it with Dev-C++ and it seemed to work ok. The only change I had to make was to flush the input stream after selecting a menu. You should not use scanf() especially with strings because it will allow you to type more characters than the input buffer will hold, causing buffer overflow. It also leaves <Enter> keys in the keyboard buffer so that the next time you call scanf() or getchar() these functions will not appear to do anything. The standard C solution is to use fgets() to get the inputs when use atol() to convert the input buffer to integer when necessary. For example:

fgets(STU->FName,sizeof(STU->FName),stdin);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>> GlobalMirror2(&GlobalMirror,2);

You can't do that after the object has been constructed. You can only do it when actually instantiating the object. You need to write an initializer method or other method that can be called to initialize those classes, something like this

GlobalMirror2.initialize(&GlobalMirror,2);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The only online game I have ever played it Blizzard's Diablo II Lord of Destruction. I've been playing for 10 years or so and have beaten the bad guy I don't know how many times. I now have a cheat program that gives my character godly powers so that I can just walk through the program :)

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

How does the king know that one of the slaves is stealing the gold used for making the trinkets ???
This means he must have weighed it and so he knows who the thief is ???

Please explain Mr. AD

not relevant to the problem. But I suppose he has a spy that told him, and his spy is ALWAY correct.

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

>>How do I make sure that my program gets very little priority, but just enough to watch another program

This is operating system dependent. In MS-Windows you can call SetThreadPriority() -- see MSDN for details. I don't know how its done in *nix.

Can't answer your other questions. sorry.

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

I am taking a university C++ class, but this is my very first attempt to write a program on my own.

Thanks again. That makes sense. I didn't realize I could set the IF condition to make the input equal to a char. Thought it had to be an int value.

In C and C++ the char data type is an int -- it is a one-byte integer. There really is no such thing as a true character data type, the characters you see on the screen are represented internally as integers, for example the letter 'A' has a numeric value of 65. You can find out the values of all of them in an ascii chart..

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

Please read this and post your code when you are ready.

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

Please read this thread about how to post code inside code tags so that spaces and tabs are preserved. There are also other helpful threads for newbes at the top of this board that contain links to other useful information.

Thank you, and welcome to DaniWeb:)

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

its been a long time, but I think you can use it on core files too. If your program produces a core dump you can use gdb on that core file.

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

VC++ 6.0 was released in 1998 and the current c++ standards was released in Oct 1998. Borland 5.5 compiler was released in 2000, which is not enough time to have included very much, if any, of the C++ standards.

And yes, 6 years is a long long time for compilers to be around.

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

I didn't use the e-mail method -- after answering the last question it started asking me to sign up for some advertisements -- I just kept hitting the continue button and after 20 or so ads I finally got to the results page. I guess they gave up on trying to make my wallet loose weight.