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

It will depend on what operating system you are using. This is a pretty standard tutorial for MS-Windows.

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

You know, I suspect that many billionaires are ecstatically happy.

I'm a little sloooow and don't get the connection :confused:

[edit]Ohhhh! I get it now. You were talking about my signature :) [/edit]

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

It sounds like a math problem not a programming problem (combination theory). How many combinations are there in N values taken two at a time? If there were just 2 points, X and Y, there would be just one line. Given 3 points, X, Y, and Z, there would be 3 lines. etc. There must be a mathametical formula for that series, but I don't know what it would be. google for combination theory and you will find lots of mathametical models.

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

You could skip the call to the function and just write this

std::cout<<"Time taken == "<<static_cast<double(t2-t2)/CLOCKS_PER_SEC;

You could wrap the static part in a funcit

Skipping the call to the Multiply function would defeat the whole purpose of the program. And diff() returns seconds, not milliseconds, so the division you posted will not work anyway.

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

0 seconds is probably correct. Computers will execute that code in just a few nanoseconds. Call clock() instead of time() because clock() has higher resolution. But that too may result in 0. If it does, then call that Multiply function several hundred times and take the average time.

clock_t t1, t2;
for (int i = 0; i < 5; i++)
    {
    t1 = clock();

    for(int k = 0; k < 1000; i++)
        A.Multiply(B);

    t2 = clock();
    dif = t2 - t1;

    cout << "This took "<< dif << " miliseconds" << endl;
    }
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Whether or not there is computational time will be compiler dependent. Assuming you have a good optimizing compiler and do NOT compile the program for debug, the compiler will may or may not toss out any storage for constants and keep the value in registers. That, however, is pretty unlikely with Intel (or compatible) processors due to limited number of registers. So most likely some CPU time will be spent loading a register with the storage location of the const variable before it can be used for anything. So whether that variable is an int or a const int makes no difference because it still will have to be store some place.

The same program compiled on a machine with a different CPU type may handle const completely differently.

So the short answer to your question is -- maybe yes and maybe no

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

Here is just one of many links to that subject which you can find. In addition to leaving the '\n' in the keyboard buffer, as you have already found out, scanf() has a huge security issue as shown in the link I just gave you. scanf() will let you enter as many characters as you like and will blindly scribble them all over memory if the buffer is not large enough to hold them.

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

>>for (int index =0; index < size * 2; index++)

Delete that line.

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

Thanks for the quick responses.

What I'm really wondering is whether giving the const qualifier really does facilitate any compiler optimizations (in the case of a variable which is local to a function and only assigned upon initialization).

Read Necrolin's post.

-I'm wondering if hunting down and clarifying all these cases in a moderately large software project will yield any tangible benefit (besides stylistic improvement).

No. If you are trying to optimize a program, look elsewhere. You might save a couple nanoseconds, but that's about it. I would not bother with such changes unless there is something else to change too.

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

How would that reduce the problem? Now if there was a fee for each post :) :) :) But that would probably eliminate everything in Geeks' Lounge, except for those members who have too much money.

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

>>I do not understand why jump statements are so frowned upon.
Because it results in spaghetti code which is difficult to read and understand.

>>Anywho, I would prefer to use scanf over getchar.
I didn't say getchar(). I said fgets(). Doesn't matter whether you or I like it or not -- scanf() is a crappy function that does crappy things to the program. Get over it and use functions that actually work.

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

An array of 22 2x2 arrays is declared char matrix[22][2][2];

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

>>I am getting stuck in an infinite loop when I input a character instead of an integer during a scanf("%d"....);

That's why I always (or normally) use fgets() instead of scanf(), then after validating input convert the text to an int.

C language does not provide a standard way to clear the keyboard buffer of all unwanted keys, but fgets() does. If the last character of fgets() is not '\n' then there will be more keys avaiable from stdin.

>>start: // I use this to restart the program
In C language you should use a loop, not jump statements. You could use do loops or for loops to do that. For example

bool done = false;
do
{
    ...
    switch( command )
    {
      ...
      case 11: // quit
      done = true;
      break;
    }
} while( done == false );
jephthah commented: yes +6
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Think of a 2 dimensional array like a checkers board, which has rows and columns of squares. Or you could think in terms of an electronic spreadsheet. In a 2d array the first dimension represents the rows and the second dimension represents the columns.

You might declare a spreadsheet that has 10 rows of 3 columns each like this:

int array[10][3];

and to reference row 3 column 2 array[3][2] = 0; That's really all there is to it. Just remember that C language counts rows and columns starting with 0, not 1, so the columns are numbered 0, 1 and 2 and the rows are 0, 1, 2, ... 9.

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

First I suppose you will want to create a structure to hold all the data for a patient. And you will want to make a linked list of those structures so that you can easily add new patients when needed.

Once you do that you might be ready to write the file i/o code. The simplest and quickest way to write the patient data to a file is in binary mode where the entire structure is written at one time and with one line of c code. The problem with that is it can not be easily read with another program such as Notepad.exe or any other text editor.

If you want to see the file with a text editor then you will have to write each field of the structure in text mode. This is a little more difficult to code and more time consuming to run but at lest you will be able to view the file with a text editor.

Another method, which is even more complicated, is to save the data in an SQL database, such as MS-Access or SqLite. This would require you to learn the SQL language in order to maintain the database. SqLite might be the ideal database for your project because it's small and does not require an outside database engine like MS-Access installed on the computer.

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

So what do you need help with? We are not going to write that program for you, so you might as well get started.

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

line 21 should be sprintf(), not printf()

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

My guess is that you are including MyClass.ini on two or more *.cpp files. objects can not be declared in header files because it causes the multiple declaration link errors that you have.

Suggest you do not use MyClass.ini at all. Instead, put the initialization in one, and only one, *.cpp, such as MyClass.cpp

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

According to this Canada has the best sky resorts in the world. So I would expect Canadians to be top-knotch at winter sports, and they proved that during the Olympics.

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

main() is passing integers, but the va on line 27 is trying to get floats. Change main() to pass floats. Function1(3, 1.0F, 2.0F, 3.0F);

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

You will have to post a little code snippet of what you are trying to do. A typedef itself does nothing, so using strstr() on a typedef is meaningless.

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

The comparison function is comparing addresses, not the values that are in the structures

int indirectstructsortbyid(const void *i1, const void *i2)  {
    struct mys **a = (struct mys **)i1;
    struct mys **b = (struct mys **)i2;
    return (*b)->id - (*a)->id;
}

[edit]^^ Adak beat me to it.[/edit]

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

Your compiler does not support threads. You will have to use a modern compiler such as Code::Blocks or VC++ 2008 Express, both are free for the downloading.

Salem commented: Yes +19
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

strstr() is used to find a string within another string. For example, it would check if "World" is contained in the string "Hello World". strstr() is not related to structures or typedef struct.

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

The first parameter is a two dimenaional array of characters, declared something like this: char grid[20][MAX_Y]; . The second parameter is a single Line object passed by reference.

char grid[5][MAX_Y];
Line line;
drawLineInGrid(grid,line)

I assume you need to initialize the grid with some values before calling that function.

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

>>intset.cpp:16: error: prototype for âIntegerSet::IntegerSet(int*)â does not matc

That means the constructor in the *.cpp file says the parameter is an int array, but in the *.h file it says the parameter is a single integer.

>>main.cpp:36: error: invalid conversion from âint*â to âintâ
Same problem as above. Fix the first problem and it will probably fix the problem on line 36 of main() as well.

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

When line 2 failes that function should return right away instead of processing the rest of that function.

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

That's why you should write and debug such programs in small sections. I suppose you are using *nix, so learn to use a debugger such as dbg, which will pinpoint the seg fault for you by using the core file. The program first has to be compiled for debug -- I think its the -g option.

Salem commented: Nice +19
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Now create a file with an escape, and run your program with input redirected from it.
.

Why would I want to do that when all I want is to capture the Esc when pressed at the keyboard (and without pressing the Enter key too)?

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

Congrats on your first 1000 posts :) I was pretty thrilled about it too so I know how you feel.

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

In Borland 5.5 is erases the input.

Oh yes, vc++ 2008 express does that too. Hadn't noticed that because I had not typed any other characters before Esc key. But I see that behavior now.

I dual booted into Ubuntu and tried the same program. There pressing Esc prints ^[ until ^C is pressed, then it prints 27 for each time Esc was pressed.

Neither MS-Windows nor *nix produces the desired result. The only way I have found to get the desired result is with the functions in conio.h or using something like ncurses.

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

Sorry but hitting the Esc key does nothing with vc++ 2008 express on Windows 7 Home Premium

int main()
{
    int ch;
    while((ch = getchar()) != EOF)
        printf("%d\n",ch);
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

That's wrong. Remove the "== 0" part. See line 32 of the code snippet I wrote.

If ( info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
{
        printf("sub directory found \n");
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

AFAIK ESC can not be detected using standard i/o, such as getchar() and fgets(). Same with other special keys such as function and arrow keys.

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

The idea for what you want to do is the same in both c and c++. If you are calling FindFirstFile() and FindNextFile(), just check the dwFileAttributes member of the WIN32_FIND_DATA structure to see if the file is a folder -- FILE_ATTRIBUTE_DIRECTORY. If it is, then do recursive call to the function like I wrote in that code snippet.

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

See this code snippet I posted here about 5 years ago.

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

It will depend on the operating system and compiler you are using.

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

in MS-Windows the two classes could communicate one class sending a private message to the other via win32 api SendMessage(). The gui class would process the message just like it processes all other windows mesages.

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

The scope operator is c++, not C. In C give the variables different names so that you, and the compiler don't get confused.

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

Suggest you start here.

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

if( windspeed >= -40 && windspeed <= 40) When working with negative numbers the operation is the reverse of positive numbers. That is, -50 is less than, not greater than, -40.

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

Memory for all types of static variables is allocated when the program is compiled, just the same as when memory is allocated to normal global variables. When your compiler creates the executable program that program includes memory for all the functions that you wrote (or linked with in libraries) as well as global and static variables. The operating system deals with all that when it loads the program into memory.

In short, memory allocation for the three cases you described are all identical.

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

I go to the universty of sussex studying ComSci ther mate year 2 ooh yeee, why dya ask? No offence btw but Isn't brookes a failed excuse compared to oxford university?

Off-Topic: According to this, Cambridge is the best university in UK. Oxford ranks 5th in the world, which is still a great ranking.

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

wrong compiler. Use either Code::Blocks or VC++ 2008 Express (both are free) so that the program can take advantage of up to 2 gig RAM and huge data files. The compiler you want to use can't either of those. You will also learn how to write a modern c++ program and possibly write a gui program instead of a text based program.

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

combine the loops on lines 31 and 37 because there should only be one loop, not two.

while( infile >> lname >> fname >> midInitial )
{
    file2 = fname + lname + ".dat";
    ifstream in(file2.c_str());
    if( in.is_open())
    {
         while( in >> ton )
         {
              // do stuff here
         }
    }
}