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

line 14 of CMain.h -- global objects can not be declared in header files because the compiler will try to create them in each *.cpp file in which the header file is included. Instead, use the extern keyword in the header file then in one, and only one *.cpp file declare the object without the extern keyword.

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

I realize I'm a little late in this thread. RGB() in windows.h is just a #define and as such you do not need to use any of windows libraries. Just put this in your program. #define RGB(r,g,b) ((COLORREF)(((BYTE)(r)|((WORD)((BYTE)(g))<<8))|(((DWORD)(BYTE)(b))<<16))) A COLORREF is nothing more than typedef unsigned long COLORREF; So, you could do something like

switch(RGB(20,30,40) )
{
    case RGB(20,30,40):
}
josolanes commented: I appreciate all your help!! Will try it with COLORREF +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

edlin was a really nice text editor for its time. I did all my C program using it for MS-DOS.

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

switches with multiple variables is no supported, just as you thought it might not be. But ... if you convert the rgb values into COLORREF value then you could use that in the switch statement.

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

At least two problems with your program.

  1. The space is not the only character that is considered white space. It also consists of tabs, back spaces, and returns '\n'. The safest way to check for all these is to use the macro isspace().
  2. You can not use fstream's >> operator to read white space because >> always skips white space. What you want is to use fstream's get() method which does uninterpreted reads, much like calling read() for a single character.
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Quick question... How are you supposed to edit the test ?

That was one of the OP's questions in his original post.

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

>>Need an answer

The answer is to use google.

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

Did you compile with the project that I posted?

This is the options I selected when I created the project

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

I just created a win32 console program and your code compiled without error. vc++ 2008 express compiler. My project is attached if you want to look at it.

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

>> int goodLinks[kWordL + 1][kLinksL];

That's the culprit that is causing stack overflow. Make it a pointer and allocate the memory with new.

You are also going to have lots of problems with concantinating ".txt" to the pointers such as filename cause those pointers were never allocated enough space to hold the additional text. Suggest you replace all those pointers with std::string to avoid those problems. For example

std::string fileName = "None";
	std::string dictionaryName = "None";
	std::string sequenceFileName;
	string lastFileName = "None";

When you do that you will also have to change the function parameters to use std::string. Well, you really don't HAVE to do that but it would make your program a lot safer. Other changes will be needed too.

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

Don't know yet because I need a clean compile.

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

There are lots of these

1>c:\dvlp\test10\test10\test10.cpp(659) : warning C4258: 'i' : definition from the for loop is ignored; the definition from the enclosing scope is used
1> c:\dvlp\test10\test10\utils.cpp(646) : definition of 'i' ignored

Although they are warnings you need to correct the problems because they are actual errors. It is trying to tell you what you have attempted to use the value of a loop counter that was declared inside a for loop, which is not legal in c++.

for(int i = 0; <snipped> )

if( i == something) // illegal because i was declared above
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

>>int __cdecl main(void)
Remove __cdecl because it isn't needed. The compiler will generate the correct code without it. The c and c++ standards do not allow other kinds of function declarations.

Don't know the answer to your question. Are you trying to compile that code as a C++/CLR project? If yes, then I think you created the wrong project type. Create a c++ console project.

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

what version of vs are you using? I tried to compile that *.cpp file using VC++ 2008 Express and get lots of errors. There have been lots of changes between vc++ 6.0 and 2008, so you might want to compile it with 2008.

Also, please post randomc.h

lukebradford commented: Thanks for the help! +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

you might want to get a copy of edlin line editor and see how it worked.

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

No. But you could open a socket to another computer and ask it what time it is. Read this link

Salem commented: Nice +19
jonsca commented: What if the other PC isn't wearing a watch? +2
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

I agree -- when splitting a hijacked post the mods are adding hijack to the new thread's title. Makes it easy to know why the first post in the new thread might be a little confusing.

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

Yes, do the same thing for date. There is another way to write that function to avoid the static declaration of the buffer.

const char* gettime(char *inputbuf)
{
   // other code here
    return inputbuf;
}

You could also use strftime() but I never use that function because doing it myself is just as easy.

Look at struct tm in time.h and you will see the names of the date and time members.

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

you mean something like this:

const char* gettime()
{
    static char curtime[20];
    time_t now = time(0);
    struct tm* tm = localtime(&now);
    sprintf(curtime,"%02d:%02d:%02d",
          tm->tm_hour, tm->tm_min, tm->tm_sec);
    return curtime;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

VC++ 2008 has some problems with viewing the values of variables, I think it gets confused sometimes.

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

>>Is this a 64 bit issue? Im on a x64 project..

Not if you are compiling with a 32-bit compiler. It's the compiler, not the os, that determines 32 or 64-bit programs. But I doubt that is the case. Post some code that demonstrates the problem.

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

I am using char * for getting data from the user. Now, if i just do

char * data = new char[100];
cin >> data;

The data is corrupted, i.e. only data before whitespace is stored; and the following is an example result:

enter: "Microsoft Co."
data: "Microsoft"

Can someone tell me why this thing happens?

It has nothing to do with dynamic memory allocation. The >> operator stops at the first white space. If you want text that includes spaces then you need to use getline(). Using std::string is preferred but you can use character arrays too. cin.getline(data, 100);

Also, secondly, I want to avoid declaring a size to the char *, since i want the input to be flexible. Now, the following code says that the 'data' is not initailized when executed:

char * data;
cin >> data;

Any idea how to come around this?

Thanks!

Your compiler is correct, you can not use a pointer before it has been allocated, as in your first example. The solution you are seeking is in std::string. With that class you do not need to specify the string's length, and can be used almost exactly like a character array.

std::string data;
getline(cin, data);
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

how is slistelem declared?

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

>> if (temp == c)

Your compiler is correct. Variable c is a single character, not a character array. Maybe you mean if (temp[i] == c)

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

why don't you just use sprintf()? With sprintf() you can do all that in one line of code. Do not put spaces in the date string because many programs have problems with the spaces, and arrange the string so that the file names can be easily sorted using Windows Explorer or some other program.

char filename[40];
sprintf(filename,"%04d%02d%02d", timeinfo->tm_year+190, 
    timeinfo->tm_mon,timeinfo->tm_mday);

>>file.open((const char*)g, ios_base::app);
The typecase is unnecessary.

>>if (!file) cout<<"error"<<endl;
It's good that you make that check, but if open fails then don't execute the lines that follow. So you should code this:

if( !file.is_open() )
{
    cout << "error\n"; // endl is unnecessary
}
else
{
   // do something
}
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

blobs are nothing more or less than large chunks of binary data. The database knows nothing about the blob's contents, its up to your program to interpret that. Here is one article that may help you.

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

That link to Turbo C++ Explorer 2006 is incorrect.

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

>>Base * ReturnPtrToANewBaseClassObject()
In base.cpp you forgot to add the Base:: class scope Base * Base::ReturnPtrToANewBaseClassObject()

Carrots commented: Thanks ever so much for your help! +1
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

The problem is with tutorials found on google, they are written by people who do not have a proper grasp or understanding on the subject, they skim over important information and don't have the real world experience to give real insight.

Oh yes I have to agree with you on that one. Tutorials are only useful in the short term, not meant to provide in-depth discussions of the topic. And often they can be outdated or flat-out wrong. Currently printed books (which sometimes give incorrect information) are preferred.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
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

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

>>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

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

>>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

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

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

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

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

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

>>int personaladdressbook[50];


Almost struct addressbook personaladdressbook[50];

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

I wouldn't make duplicates of A and B, but put the results in matrix C so that A and B are left unchanged.

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

lines 81 and 84. I see no object named "addressbook". There is of course a structure by that name, but no object. Create an object of that type, (don't use the same name as the structure to prevent confusion)