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

Mine was from about 20 years ago when I played Dungeons and Dragons role playing board game. It has nothing to do with my real-life race -- I'm a WASP, not Chinese.

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

You can't fix it with that compiler because that compiler version is too old. Get free Code::Blocks with MinGW (link here), which is current.

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

>The constructor was used only to initialize *head=NULL,

No it isn't. Read your code again -- its the same as I suggested.

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

lines 173 - 194: Do not put executable code inside header files, move those two functions into a *.cpp file like GameUnit.cpp. The same goes for Player.h.

After making the above changes everything compiled ok for me. I just added two more files: GameUnit.cpp and Player.cpp

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

I like having a tool nearby that can give me answers from the web, scan bar codes, give me GPS directions, be a bubble level, etc, etc. It's there when and where I need it in ways that make me more efficient.

I do too, but that's much different than people who constantly have a cell phone nailed to an ear.

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

*head = NULL in the constructor is probably incorrect. How did you declare variable head? If something like this: char* head; then in the constructor it should be head = NULL; (note that there is no star).

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

Post the entire program because the code snippet you posted compiles ok for me using vc++ 2010 express compiler/IDE.

[edit]I used the exact same code as ^^^ posted.

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

No. All you have to do is initialize pointers to NULL when declared, e.g. int *ptr = NULL; or set them to NULL in c++ class constructors. There is no such test for other kinds of variables.


But you can either write your own or use an existing smart pointer c++ class. google for "c++ smart pointer" and you will find examples and tutorials.

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

Use a loop. There are three kinds of loops: for loop, while loop, and do loop. Use the one that best fits the situation. Read this short tutorial

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

wrong. it calculates all days of the year up to the current date. as you can see the switch cases do not get breaked, therefore it sums up all previous months.

Oh yes :) I see it now.

Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
#include <stdio.h>

void main()
{
    int d,m,y;
    int days=0;
    int k;                            // return var
    printf("input date dd.mm.yyyy\n");
    scanf("%d.%d.%d",&d,&m,&y);
    m--;
    switch(m)
    {
        case 11:days=30;
        case 10:days+=31;
        case 9:days+=30;
        case 8:days+=31;
        case 7:days+=31;
        case 6:days+=30;
        case 5:days+=31;
        case 4:days+=30;
        case 3:days+=31;
        case 2:if((!(y%4))&&(y%100))
                   days+=29;
               else if(!(y%400))
                   days+=29;
               else
                   days+=28;
        case 1:days+=31;
        case 0:break;
    }
    k=leap(y);
    printf("days:%d\nleap year:%d\n\n",days+d,k);
}

int leap(int year)
{
    int k;
    if((!(year%4))&&(year%100))
        k=1;
    else if(!(year%400))
        k=1;
    else
        k=0;
    
    return k;
}

Nice try, but it only calculates the days for one month. What it needs is the number of days from 1 Jan to the beginning of the specified month.

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

While in Paris, you go to bed at 9:00 in the evening.

That applies here in USA too :)

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

>> for (int n=0;n<=99 ;)

What makes you think there will be 99 characters in the string? You should use this: for(int n = 0; n < words.size(); ) Also not that you should use <, not <=

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

Are you using Windows Forms program? Or something else? General, make a public function in Form2 that Form1 can call and pass the data. Form1 will have to get a pointer to Form2 in order to do that. Another way is to put the data into a common data file that can be used by both forms. MFC does that with its CDocument class, and you could easily implement something very similar.

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

>>does "cout" of iostream works?

No. You have to create the strings and use DrawText() to display them where you want them. How big is that 2d array? Now many columns and how many rows.

Lets say the array is declare as int array[5][2]; Then create the string something like this:

CString line;
for(int row = 0; row < 5; row++)
{
   for(int column = 0; column < 2; column++)
   {
        line.Format("%d", array[row][column];
        // calculate the pixel location not shown here
        pDC->DrawText(line.GetBuffer(), ... );
   }
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Torrents in and of themselves are no more illegal than any other program. Its how you use the torrent that can become a legal issue.

jbennet commented: yup thats what I was saying +0
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

Forgot to mention that CString has a Format() method which works very similar to sprintf() that you can use to format int to strings.

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

Maybe someday Dani will put that feature in PFO too. I'm getting tired of banning signature spammers.

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

>>how can i access the variables of my "xyzView.cpp" file in the Dialog Box

CDocument class contains a linked list of CView classes. So first you have to get a pointer to CWinApp by calling AFX::GetApp(), then from that pointer get a pointer to CDocument using its GetNextDocumenTemplate() method. Since MFC is just c++ you will have to make sure that the variables have public access in CWin class by either making the variables public or having public getter and setter methods.

>>but i want to know, how can i print a 2D-Array in MFC SDI?

Similar to the way you would with cout but you have to covert the data to a string first. cout makes that conversion for you -- in MFC you have to do it yourself. You can use any of the standard C or C++ functions to do that.Formatting the string is the easy part -- calculating the exact pixel location where it is to be printed may be more problematic.

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

My guess is that very few people of my age group have that disease because we grew up in an age long before cell phones and even Star Trek with their communicators. So it doesn't bother me at all to not have a cell phone implanted in my head and talking to someone all the time. I enjoy my peace and quiet.

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

The trick to writing complex programs is to break it down into much smaller parts. For example the first thing you want to do is write a program that lets you enter the date as a character array. Once you have that working, take the char array and break it down to its integer parts -- day, month, and year.

Most programs that calculate that sort of thing use an array for very quick lookup of the number of days from 1 Jan to the 1st day of the desired month. We know that January always has 31 days, as do several other months. So we can just create an array like this:

int days_of_months[] = {31, // January
                        28, // February
                        31, // March
                    // etc for all 12 months
};

And for days in year

int days_in_year[] = {0, // January
                      31, // 1 Jan to 1 Feb
                      59, // 1 Jan to 1 March (ignoring leap year)
                      89, // 1 Jan to 1 apr
                // etc. etc for the remaining months
};

With the above, its pretty simple to figure out the number of days from 1 Jan to the 1st day of any given month by just using the month number as the index into the array. int days = days_in_year[ month ]; Once you have done that, then just add the day of the current month. So if you have a date string "15 February 2012" (where January = 0, February = …

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

That's because you have to either add a call to keyboard input so that the program waits for you to press a key, or run it in its own cmd window.

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

I would first put something at the end of the array to indicate there is no more data -- that way the program knows when it is done. The last byte in the array could be either another $ or binary 0, but anything except numeric digits could be used too. After that, just modify the code you have to keep looping through the array's memory until end-of-array byte is found. You might want to put the code in another function then repeatedly call that function for each item in the array.

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

The tutorial I posted will show you how to connect the points.

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

This Scribble tutorial will show you how to draw lines with MFC

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

you are asking for a very very long list of #ifdef's.

doing real code portablity is very difficult. every system has different APIs. linux, the flavors of BSD, AIX, SUNOS if it's still used, solaris, SGI, HPUX, the one with the trademark we dare don't touch, minix, centos, qnx, etc.

to do code portability, terminal emulation packages have been developed such as ncurses (no curses).

I doubt the op cares after 4 years.

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

See this thread for some hints

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

[edit]what ^^^ said.

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

Either vc++ 2010 or Code::blocks will work (assuming you are using MS-Windows). vi or Code::Blocks on *inx.

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

They worked ok for me -- the links are a list of google links

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

You don't link the database itself, but a library of functions. There are at least two ways to do this:
1) ODBC -- see this tutorial

2) ADO -- tutorials here

Both the above require a good deal of programming and require a good grasp of c or c++ languages. Some of the tutorials are written for vb, but they apply to c/c++ too.

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

>>w = strcpy(text),
No

>> would i need to declare two new char[] array
No, just use the same char array. Assume you have a for loop with i counter, and the character at text == a vowel you want to delete strcpy(&text[i], &text[i+1]);

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

Code::Blocks is not a compiler, its an IDE very much like notepad++.

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

Not to hijack the thread (though the OP hasn't posted here since 2009), but I am presently looking around for a free C++ IDE/compiler myself. Would you recommend Code::Blocks over Visual C++ 2010 Express, or even something else?

Use Code::Blocks if you want to write portable programs -- its supported on MS-Windows, *nix and MAC. VC++ 2010 is only for MS-Windows, but is the easiest to write MS-Windows programs with any or a combination of several .net languages.

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

@capton: If you are using Code::Blocks why would you want to use Notepad++? Doesn't make any sense.

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

The guy who posted using goto, once again assuming you're replying to me. Could you be more clear with whom you're replying to and why, please?

I was replying to your post that has 2 negative reps. But after re-reading this thread I realize you did not post the goto statement and I apologize for accusing you of doing that.

>>Since two people have deigned to give me negative rep, I

You don't have two negative reps, the poster of the goto code has it.

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

Send me a copy of the program and I'll test it on my computer. Might be a problem with the pc you're trying to use.

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

>> kingsonprisonic.

???

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

The negative rep probably was for your use of the goto statement instead of the more standard loop. The code you posted does not even attempt to do what you just described.

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

I would use std::string's substr() method if( tokens[0].substr(0,2) == "cd")

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

just use getline() instead of cin >>. The rest should work as it is, except at the end when you want to display all of the tokens

for(int i = 0; i < tokens.size(); i++)
   cout << tokens[i] << '\n';

or if you want to use an iterator

vector<string>::iterator it;
for( it = tokens.begin(); it != tokens.end(); it++)
   cout << *it << '\n';
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You can't use cin >> for strings that may contain spaces because cin will stop at the first white space (spaces and tabs) character. If you want white space in the string then use getline()

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

class constructors are private, so you will not be able to use that class for anything.

The second constructor is setting a pointer to some other object -- a very very bad idea because when the other object is destroyed the pointer in MyClass will become invalid. You need to allocate space for the string similar to what you do in the first constructor, then copy the data from oObj into it so that MyClass has complete control and ownership of the data.

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

google for "berkley socket tutorial" or "posix socket tutorial"

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

I think I understand now, you don't want to remove vowels and spaces, just the vowels. When you find a vowel just sift all the remaining characters left so that they overwrite the vowel. You can use either memmov(), strcpy() or a loop to do that. Just make sure not to try this with a string literal or a pointer to a string literal because they can not be changed and your program will most likely crash.

As fistPerson already said, if you use std::string then you just call it's erase() method.


As for getline(), its very simple:

char text[100];
cin.getline(text, sizeof(text));
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

You don't. Notepad is just a text editor, not a compiler. Code::Blocks is distributed with a greate compiler. when you download CB get the distribution that contains MinGW compiler.

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

If you are writing a c++ program why are you using c's gets() function instead of c++ cin or getline()?

>>if (test=='a' || test=='e' || test=='i' || test=='o' || test=='u' || test=='A' || test=='E' || test=='I' || test=='O' || test=='U') {
test=' ';


Probably easier to use a switch statement

switch( tolower(test[i]) )
{
   case 'a': case 'e': case 'i': case 'o': case 'u': case ' ': case '\t':
       // do somethking
       break;
}
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

There are lots of sort algorithms -- google for "bubble sort", which is the easiest one to write. Or you could use cl++ std::sort function.

#include <string>
#include <algorithm>

int main()
{
   std::string s = "acefd";
   std::sort(s.begin(),s.end());
]
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster

why aren't you just reading the data as integers instead of strings? It would be a lot simpler and you won't have to worry about spaces. I'd put the data into a 2d array of ints which would then be easy to sort.