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

I am using IE7 and really like it -- I see no reason now to use FireFox. The only reason I used it before was because of the tabs, and now Microsoft as borrowed that idea. I don't see any advantage of running FireFox over IE7.

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

doesn't make any sense. why is b++ inside that if statement?

And what is your question? (Don't just repeat the assignment like you did in your other post). You need to learn how to ask intelligent questions, not just repeat what your teacher asked you to do.

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

that is not a question -- it is your assignment. you already have a function that returns the larger of two values. So just write a function called bigger that returns the largest value in an array.

int bigger(int array[], int arraySize)
{
   // put your code here

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

#include <stdio.h>

int bitcount(unsigned x);

main()
{
int b;
int x;

for (b=0; x!=0; x >>=1)
{
if (x & 01)
{
btt ; <<< what is this for?
}
}

return b;

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

well, that's a little better. You still did not use code tags (see Andor's post for a link on how to do that).

More importantly, what is the question? Did you attempt to compile that code? what error(s) did your compiler produce?

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

I don't know the first thing about it, but from what little I found in google links it looks like it is pretty involved. Scroll down the page and you will find some free source code. I don't know how good it is so use it at your own risk.

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

Shermaine: you need to edit your post and reformat that code to make it readable -- I'm not going to read that crap!

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

>>may i know how should i write to prompt user to enter the four weights from the keyboard.

just create a loop for this

int i;
float weights[4] = {0};
char buf[80];
for(i = 0; i < 4; ++i)
{
   printf("Enter weight #%d", i+1);
   fgets(buf,sizeof(buf),stdin);
   weights[i] = atof(buf);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
#include <stdio.h>
int bitcount(unsigned x)
main()
{
int b;
for (B=0; x!=0; x >>=1) <<< Where are these variables declared?
if (x &01)
btt  <<< what the he!! is this??? 
return b;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

main() always returns an int, never void. There are still a lot of bad examples on the net that show void main() but they are obsolete and wrong.

int main()
{
   // your code here


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

>>Okay, Iv'e finished learning C++.

:cheesy: :cheesy: :cheesy: :cheesy: :cheesy: :cheesy: you will NEVER be finished learning c++. That is a life-long task.

If you want to learn MS-Windows GUI programming here is a good introduction. Its c instead of c++ but then so is all the win32 api functions (not one of them are c++ because they can be called from many different programming languages).

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

your class declarations are terrible! One-letter variable names is highly discouraged because they mean nothing to anyone except the original author, then he will forget what they mean after a couple days.

I'd suggest starting by rewriting the classes to use more descriptive variable names. As for variable z? I have no clue because I haven't the slightest idea what that variable is used for.

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

Serendipity because I find something new almost every day, especially in these programming web sites:)

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

also

int main()
{
// this is only a 1d array of doubles because each
// salesman has only 1 row in the data file.
double arraySales[ARRAY_SIZE];
// the next array needs to be 2d because it
// is an array of strings
char arrayNames[ARRAY_SIZE][25];

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

why are those double and int arrays 2-dimensional??? Arrays must have a name. There are a couple ways you can to it. Leave the array size unspecified and pass the size as another parameter, as in your original attemp.

void PrintArray(double array[], int array_size);
void BubbleSort(double array[], int array_size);
void GetNames(double array[], int array_size);

or just not pass the size as a separate parameter, like this

void PrintArray(double array[ARRAY_SIZE]);
void BubbleSort(double array[ARRAY_SIZE]);
void GetNames(double array[ARRAY_SIZE]);

Isn't the array passed to GetNames() supposed to be an array of strings? Names normally are not arrays of doubles

void GetNames(char array[ARRAY_SIZE][25]);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why not just index into the string? You don't need a vector just to get a character from the string object.

std::string s = "Hello World";

for(size_t i = 0; i < s.length(); i++)
{
   char c = s[i];
   cout << c << "\n";
}

If you really really want to make it a vector, just do puch_back on the vector instead of cout in the above code.

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

c++ or c programs (or programs written in any other language for that matter) are unreliable at best because the os may overwrite the sectors on the next write. Even Norton Utilities is not all that reliable. MS-Windows added the trash can for exactly that purpose, when a file is deleted the os moves it into the recycle bin directory and does not really delete it at all. It would be pretty easy to write a program to move files and directories back to their original location.

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

I would add a float totalunitcost field to struct data that is the total cost for the customer. When when a line is read from the data file look up the customer record in struct data and update its total unit cost.


>>int clientNumber[4]
why is this an array of 4 integers?? all you need is one int. Same with unit cost

typedef struct Sale
{
	int clientNumber;
	char Item[45];
	char PartNum[12];
	int UniCost;
	char DayOfMonth[20];
};


typedef struct Data
{
    int clientNumber;
	char Company[34];
	char ABN[14];
	char StreetName[36];
	char Suburb[24];
	char State[11];
	char PostCode[5];
	char Phone[15];
float totalunitcost;

};

The fread line also changes somewhat. Is the client number in binary format in the file (is it readable with Notepad.exe?). If not, then this should work, if it is readable with notepad.exe then you need to use fgets() and atol()

fread(&rData[x].clientNumber,1,sizeof(int),fp);

fread(&rSale[i].UniCost,1,sizeof(int),fps);

If the integers are visible when the file is view by Notepad.exe, then you will need to use this algorithm

char buf[40];
fgets(buf,sizeof(buf),fp);
rData[x].clientNumber = atol(buf);

fgets(buf,sizeof(buf),fp);
rSale[i].UniCost = atof(buf);
// search array of struct data for customer number,
// then update total unit cost

rData[x].totalunitcost += rSale[i].UniCost;
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>can u guys help do the totalunitcost for each specific customer, i tried everything could get it done

If totalunitcost is the simple sum of rSale.UniCost, then just sum it up while reading the data file.


fread(rSale[i].UniCost,3,7,fps);
totalunitcost += atof(rSale[i].UniCost); // assume this is a float
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

open() function takes a char*, not a std::string.

inFile.open(path.c_str());
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

thanks for you reply in advance.
what I want is just "how could I implement the CURSOR by Mysql C API?"
our project is only work in C(the entire system is compiled by gcc), so I didn't know how ODBC could work here also(I never used ODBC before).

ODBC can be accessed via several languages -- C, C++, java, perl, php, vb, and probably many others.

You probably don't need to set up a cursor at all. ODBC contains functions that will retrieve the result set one row at a time. All you have to do is put the SELECT statement in a C string, send it to the database using ODBC function, then create a loop to call ODBC fetch() until fetch() tells your program there is no more data.

I realize you want just a "quick and dirty" fix for your problem, but often that is not a good long-term solution. If this project is for where you work then it will be to your advantage, and your company's advantage, for you to spend a few days to learn ODBC. It doesn't really replace the code you have now but is a different way of accessing databases. ODBC still uses SQL language, but unlike the code you have now ODBC will send it to the database server to be processed.


[edit] Here is a good C tutorial.[/edit]

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

I always used another PC (or laptop) that ran a program to read the data from the serial port. Didn't have a problem, unless the ports were set up differently.

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

I don't know, but your research might start here.

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

Use CComboBox's methods GetItemDataPtr() and SetItemDataPtr() to attach the structure to an item in the combo box.

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

lovely code -- but what is your question ? please edit your post to include code tags.

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

since you are going to rewrite the program you might as well use ODBC to make it more generic to any database -- next time the database changes you won't have to change the c code very much. google for "odbc" and you will find lots of c++ classes and other C function libraries.

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

According to Microsoft site that version is still in beta so it may not work at all on Mobile wireless devices.

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

he does need the PSDK, as the versions shipped with VC6 are so far outdated that VC2005 will not work with them.
VC2005 requires the latest version of the PSDK.

I meant he doesn't need the psdk with VC++ 6.0 but he does need it with VC++ 2005 express.

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

certifications --- hummmm. I have a HS graduation certificate, a marriage license, associates of arts degree, several medals from viet nam, a military retirement certificate, a social security card, a i will be getting an old-age social security retirement certificate in a couple years. I think that's enough certifications for one lifetime.:mrgreen: :eek: :rolleyes:

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

a minute? pitiful..you call yourself a moderator? whatever the heck that is?

lol_hacker101

A Moderator is someone who likes to answer other people questions or silly comments, such as yours.:)

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

It works because CBrush and CPen are derived from class CGdiObject, which has an operator void* that is being called when you leave out the & symbol. So the & symbol in this case is optional.

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

save and restore the original pen value. Some other part of the program may be expecting the pen to be the original value and your program doesn't want to pull the rug out from under it. Your program needs to be a little kinder and a little gentler about other parts of the program.

Grunt commented: Ah, windows guy-[Gr] +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

please edit your post and insert code tags so that my eyes will not hurt so bad when I read your code.:eek: :eek:

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

yes its using undefined behavior too. You can't just hardcode an address into the program like that and expect it to work because only the computer knows where an object's address, unless you are using some obscure operating system such as some embedded systems.

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

since you can't even use the keyboard I see no other option but to reinstall the os from CD unless you have a backup of the registry on another disk.

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

now you are asking a completly different question. vectors of what? strings? do you want to create a vector that is a union of two other vectors, where each string in the new vector is the union of the corresponding strings in two or more other vectors? The algorithm would be almost identical to what has already been posted.

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

>>Why does it jump back to the turbo c window when I press enter to enter my age? Is this wrong?


because you didn't tell the program to do anything else. If you want it to wait so that you can see what's on the screen, put a getch() at the end so that it will wait for keybord input.

After calling scanf() with an integer, the scanf() function does not remove the <Enter> key from the keyboard buffer. You must flush the input buffer or else the program won't wait for the next getch() .

int main()
{
    float years, days;
    printf ("Please type your age in years:");
    scanf ( "%f", &years);
   getchar(); // remove '\n' from keyboard buffer
    days = years * 365;
    printf ("You are%.1f days old.\n", days);
   getchar();
   return 0;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>I was thinking of making the while statement a function and calling it with main

Yes, that would be my suggestion too.

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

nicko, thats my post. thanks anywayy

Your solution was nearly identicale to mine except your made a check to insure duplicates are not inserted into the new string. If you already knew the solution why did you post the question in this thread?:eek: :?: :rolleyes:

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

If you are going to use MFC then you should have created an MFC program, not a win32 windows program.

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

anyone know where to buy it? I checked M$ site but they only linked to hardware manufacturers, such as Dell, HP, and IBM. All I want is the os, I already have the hardware.

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

>>how about a rally driver, or heck even a police car driver on route to an incident?
those people are not driving at 300+ mph!


>>That aside, do you think a F1 driver 'deserves it' if he crashes and is killed

he knows the risks before he started. Whether he diserved it or not depends on the circumstances.

hammond on the otherhand, had to be a nutcase who gets his kicks by driving really really fast automobils. I have little, or no, sympathy for people like that. I feel more compasion for his surviving family who will have to spend the rest of their lives without him.

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

A union is just a structure in which all objects occupy the same space. For example

union 
{
   int a;
   char buf[20];
   float b;
   double c;
}

In the above, the union has only one real object but it can be used by any of the names provided, such as a, b, c or buf. The size of the union is always the size of its largest object, 20 in this case. So what you need to do is make a union between the INSTRUCTION strucure and an unsigned long integer.

uinion
{
    INSTRUCTION ins;
    unsigned long ln;
};

Since sizeof(INSTRUCTION) is the same as sizeof(ln), whatever you set ln to be will be reflected in the ins structure. So if you set ln = 0x8800080000004D2, then you can get the individual bits by using the ins structure.

leonpwhirl commented: helpful in answering questions. +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

anyone driving that fast diserves whatever he gets. That's called "the theory of evolution at work", or "survival of the fitest". Hopefully he did not pass along his bad genes to any children.

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

>>cout<< ((A*)3)->get() << endl;

This is using undefined behavor techniques. 3 isprobably not a valid address for an object of type class A.

A* pA = new A; // allocate an instance of the class
pA->get();
// 
// and don't forget to deallocate it
delete pA;

Another way to do it is to make the pointer point to an already existing object of the class

A a; // an instance of class A
A* pA = &a; // pointer to the object
//
//
// you do NOT delete the pointer
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>Can I control this by putting some kind of attibute or pragma to define a section for that particular function (ten)?

I never heard if a section, there is no such thing in standard C language.

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

you didn't say what operating system you are using. XP is on a bootable CD, so just insert that CD and reboot your computer. Then reinstall the os on top of the current os.

Next time, back up the registry before you start screwing around with it.

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

boot.ini file is normally in the c:\ root directory. In Explorer turn on the option to see hidden and system files if you need to, then check the root directory to see if it is there. If it is, send it to Notepad and paste the contents to your respose in this thread so we can see it. Make sure you do NOT change the contents of that file!

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

Not certain about your question -- can a function declared in one file call a function in another file? Yes, the program has two or more files they all must be linked together into one executable program. How to do that depends on the compiler you are using because every compiler is a little different.

What compiler and operating system?

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

attached is a quicky example that I created with VC++ 2005 Pro. I did similar with VC++ 6.0 but did not attach it. There is nothing special about the project, just created a normal MFC project and set the view type to CFormView.