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

any one can u plz tell me the code for sorting 10 numbers using C++ codes

put the numbers in an array then google for bubblesort.

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

You mean after 15 days you still have not figured out how to write this program? The easiest way to display all the data for an (nearly) unlimited number of modules is to use a grid control which is something like a spreadsheet. Here is a free one that's written in C# language.

And reading/writing to text files is not all that complicated -- it ain't rocket science. Here is a short tutorial that might get you started.

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

Yes, I actually had the statement backwords -- should have been == 0 as previously noted.

The not operator ! means 0, not false. There is no requirement for false to be 0.

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

Overpriced items is no reason to steal them. Start your own business/company, make something similar, then sell them at a more reasonable price, which shuld quickly put the original company out of business. Open source program as normally just given away for free. Take Open Office as an example. It hasn't put Microsoft out of business with Office 2010, but its a pretty good competitor.

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

There is no such thing as = !!. What you want is != 0

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

One common c++ exercise is: Write a recursive function that gathers a list of all the files and folders on the hard drive, starting with a folder specified by the user. You will need to maintain either a std::vector or std::list (your choice) of all the files, and the file names must contain the complete path. When finished, short the array or list alphabetially by calling std::sort and supplying it your own comparison function. Display al the files after the vector or list has been created. Note: Don't copy/paste code you might find on the net -- that's considered cheating.

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

line 11: initialize the variable to be 0, not 1. All arrays start counting at 0.

line 13: you can initialize that array to be all 0s when it is declared, elmininating the need for the loop on lines 22-25. int asciichar [223] = {0}; line 31: A for loop might work better there for(bookcnt = 0;bookcnt < books; ++bookcnt) If you want to leave the loop as a while loop then change <= to just <.


delete line 51 and use letter on line 52 instead of value. It is perfectly ok to use char data type to index into arrays because char is just a one-byte integer.

The reason you can't open the second book is because in_stream is still open for the first bok. call in_stream.close() then clear the eof error by calling in_stream.clear()

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

Move lines 27 and 28 inside the while loop so that it asks for a temperature on every iteration of the loop.


Delete the if statement on lines 30 and 31 because the program already knows how many temps to enter.

The while statement on lines 40 and 41 is not needed. You just need the if statements so keep track of the lowest and highest temps as you enter them.

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

Stack::Node says Node is a structure defined inside class Stack.

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

what's the value of variables delta and d? Is either of them 0?

The assertion failure can also be caused by something else in your program, such as writing beyond the boundries of the array. For example: o[delta*d][0] = 0; will write to non-existant element of the array. And doing that may corrupt heap memory.

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

why are you calling malloc() is a c++ program? Change it to new and see if that fixes the error. If not, then the real problem is in parts of the program that you did not post.

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

Betty Boop

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

Great. First you need to learn how to use google.

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

A simple example of what? We need to know your exact requirements before we can make any worthwhile suggestions.

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

Yes, MFC has a database class, but its not really very good when it comes to complicated requirements. If all you need is a single table using simple selects and updates the MFC classes will work well.

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

You said in your original post that you wanted to know the number of passes through the loop that it took to either find the number or determine that the number was not in the array. Otherwise the count variable can be deleted because it servers no other purpose.

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

>>also we can use the function of convert char to integer.

Please name that function. There is no standard C function because its not needed.

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

No one said programming is easy. It might be easy for some people, but for us mear mortals learning it can be difficult and very very time consuming.

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

The oldest and most common method is via ODBC. Its pretty complicated stuff. There are a few c++ classes, use google to find them too.

Another method is ADO, Microsoft has an ActiveX control for that.

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

Everything in MFC is handled via events -- messages that are passed through the event handler (Windows Message Pump)located in an MFC function that is called from main(). OnStnClicked() will not be called until program control returns back to that message pump. When OnStnClicked() returns, program control is returned back to MFC internals, not the part of the program that you are writing.

longjmp() is not supported in c++ (not related to MFC).

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

That's not binary search that I learned. looks more like linear search.

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

USA has millions and millions of visiters each year to see such places as Disney Land, Disney World, etc. Almost none of those visiters (tourists) have any problems at all, unless they are looking for problems. I doubt you will see a single person walking down a city street carrying a gun. We aren't the wild west you see in the movies.

Mexico is a different story because of the war the drug lords are having with their government. Its especially dangerous along the Mexican/American border.

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

Where in the world did you get that binary seach algorithm??? It isn't nearly that hard.

void bsearch(int a[], int size)
{
    int n = 0;
    int high,low,mid,count;
    printf("Enter number to be searched\n");
    scanf("%d", &n);
    getchar();
    high = size;
    low = 0;
    count = 0;
    do {
         mid = low + ((high - low) / 2);
        if( n > a[mid])
            low = mid+1;
        else if( n < a[mid] )
            high = mid-1;
        ++count;
    } while( a[mid] != n && low <= high);
    printf("count = %d\n", count);
    if( low > high )
        printf("%d not found\n", n);
    else
        printf("a[%d] = %d\n", mid, a[mid]);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Search www.codeproject.com -- they have thousands of free MFC classes. If you write MFC then you need to bookmark that site.

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

The best one is vc++ 2010 Express. Another very good one is Code::Blocks. google for them and you will find download links.

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

lines 8 and 9 are not pure c++, they are for managed code, which Dev-C++ can not handle.

Here is an example of how to do it. The function uses recursion to transverse the subdirectories. It builds a vector of all the file names. Feel free to change it any way you wish to adapt it to your problem.

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

Conversion is not necessary. The char data type is a one-byte integer.

char x = 2;
int y = x;

The compiler will promote the char to int during the assignment.

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

>>As for pure C you can concat char-arrays, for example:
That works too, its just a lot more typing and error prone than using sprintf(). Error prone meaning the more verbose the code the greater the chance of making mistakes. sprintf("SELECT * FROM table_name WHERE lname = '%s' and fname = '%s'", lname, fname);

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

>>The 2nd parameter confuses me a bit because its typed as an int which is a 32 bit quantity in 32 bit Windows, yet the example above shows a literal char being used

character is just a one-byte signed integer. The compiler will promote it to an integer of the required size.

In c and c++ languages there really is no such thing as a character -- they are all represented as integers. If you look at any standard ascii chart you will see what the decimal/hex value is for all 255 possible characters in the English alphabet. So, the letter 'A' for example has a decimal value of 65. You can even do mathimatical operations of characters, such as int n = 'C' - 'A' + 'B' / 'E' >>size_t bufferSize = 1024*sizeof(char); //NOT just 1024.

sizeof(char) is guaraneed to be 1, so that statement is like saying 1024*1, which makes little sense.

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

it has to be expanded.

char query[255];
sprintf(query,"SELECT %s, %s FROM table_name;",fname,lname);

But even the above is wrong because %s and %s need to represent column names, not data values. It's very unlikely the table has two columns named "John" and "Doe".

A more likely query might be "SELECT * FROM table_name WHERE lname = 'Doe' and fname = 'John'"

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

>> need help solving this. Stuck half way

Post what you have done so far. We don't do people's homework.

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

I'm not a mind reader nor am I clairvoyant.

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

Not a macro, but you can easily write a function to do that. Give it a try and see what you can gome up with.

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

If you want to deal with subfolders then you will have to start by passing *.* to FindFirst() so that it will return all files and foldes. Then your program will have to filter out the ones it wants. There have been several code snippets that illustrate how to do that -- I even posted one on DaniWeb

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

There is no point in dynamically allocating small amounts of memory. One advantage of usiong cUser[5][10] is that is is not prone to memory leaks.

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

turbo c is a 16 bit compiler and can not access win32 api function. So you can't create a windows app with it. Get a modern compiler such as Code::Blocks or VC++ 2010 Express (both are free).

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

Looks like a giant kite :) I wonder how many birds will just fly right into it.

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

LPCTSTR is typedef'ed in windows.h as const char* . So your String class will want to return a char* pointer to its character array, or whatever kind of data it holds.

class String
{
private:
   char* str;
public:
   const char* operator LPCTSTR()
   {
         return str;
   }
};
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You made incorrect changes. Delete the allocations on lines 9 thru 12 and just hard code their sizes char cUser[5][10], cPassword[5][10]; Since cLoginU is declared to contain only 10 characters, then cUser should be the same size.

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

What you have created is an array in the shape of a right triangle instead of a rectangle. Which is unusual, and now you have unused elements of the array. That may be what you intend, I don't know.

And yes, that isn't the answer to the problem. Use your debuger and fid out what is causing it.

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

If it works on MS-Windows its just by dump luck

>>line 17: lower_tri[j] = values[k];
Look at line 4 and tell me how many floats are allocated to each row of lower_tri array. Answer: Row #0 is 1 float, row #1 is 2 floats, row #3 is 3 floats etc. That means line 17 is writing beyond the boundries of the array.

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

>> char *cUser[5]
That declares an array of 5 pointers. Are you attempting to store 5 different use names in that array? If you are, then you have to allocate memory for them before they can be used. There are a couple ways to do it

1) use static allocation, such as char cUser[5][25]; which will have enough space for 5 user names, each name as maximum of 24 characters + null terminator.

2) allocate them with malloc

for(i = 0; i < 5; i++)
   cUser[i] = malloc(25);

The same applies to cPasssword.

But for the life of me I don't know why you would want to user to enter 5 differet user names and passwords? Why not just one ?

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

What happens after the third attempt?

>>(che = getch()) != EOF
EOF is only generated on MS-Windows by pressing Ctrl+Z key combination. How likely is that ever to happen in your program?

>>&& i < sizeof(pword)
variable i needs to be reset back to 0 before second and third attempts to erase the previous password so that the user can enter a new password. I'd put i = 0; on line 7, just before that while statement.

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

I suppose you didn't google and find this

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

>>fyi the police are there to protect individuals
No they are not. The police are not your personal bodyguard. There are not enough police to be everywhere and protect everyone. It is your responsibility, and yours alone, to protect yourself and your family.


In America I have the right to use deadly force against any uninvited intruder. Robbers generally do not attempt to rob homes where they know someone is at home, but it does happen and many of them are shot dead. When that does happen the robber had better be inside the home. If he is not then the shooter may be convicted of murder, unless there are other circumstances that can show the murder was justified.

>>Is it not better to leave it to the police
No because its not the police's job to protect every person and every home. If you wait for police the robbers will be long gone with either the goods or your life.

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

A composite key means the key consists of two or more fields.
"select price from item_size where field1 = "something" and field2 = "smethin else" and ..."

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

:)What you used to do all night now takes all night to do

More like: what you used to do all night is now impossible to do at all.

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

Welcome to DaniWeb. Ask your question(s) in the appropriate Software Development forum and I'm sure someone will be glad to answer them. Won't be me though because I know nothing (well almost nothing) about VB.