WolfPack 491 Posting Virtuoso Team Colleague

Steve Loughran's WinAPI FAQ

This isn't exactly starting material and maybe a bit outdated (created before Win2K). But overall covers most of the questions a newbie, who is new to programming in C and is fedup with creating Hello World console applications, may ask.

WolfPack 491 Posting Virtuoso Team Colleague

A novice lion tamer was being interviewed. “I understand your father was also a lion tamer,” the reporter queried.
“Yes, he was,” the man replied.
“Do you actually put your head in the lion’s mouth?”
“I did it only once,” said the lion tamer, “to look for Dad.”

A sportsman went to a hunting lodge and shot a record number of ducks, aided by a dog named Salesman. The following year he returned and asked the lodge’s owner for Salesman again. “That hound isn’t good anymore,” said the dog owner.
“What happened? Was he injured?”
“No. Some fool came down here and called him ‘Sales Manager’ all week. Now all he does is sit on his tail and bark.”

After lecturing her six-year son on the golden rule, the mother concluded, “Always remember that we are here in this world to help others.”
The youngster thought this over for a minute and then asked. “What are the others here for?”

WolfPack 491 Posting Virtuoso Team Colleague

Although I don't like to be seen as a Windows bigot, I don't think Linux is for anyone who has limited time in their hands. I have tried god knows how many distributions of *ix, (Gentoo, Linux from Scratch, Ubuntu, Knoppix, Redhat 7.3 to 9, Fedora 1 to 5, Turbo 10 Japanese version, FreeBSD 4.*, 5.5, 6.*, Debian, Mandrake, CentOS 4.1 -4.3 the list is endless ), but I couldn't do anything worthwhile using any of those. It was only the CentOS 4.3 that I came at least came closer to sticking with. Mandrake is the best if you want to get things up and running fast, but some geeky friends ( who are Microsoft bashers of course ) of mine said that Mandrake is slow compared to the others. Maybe they do not see anything elite in using a distribution that is easy to use. Even now, as I rummage through my CD collection I get really mad thinking about the garbage that all this has generated.

Before the Download managers like APT and Yum came in to play, installing software was pure hell. Even now if the dependencies are not in the repository, good luck if you are trying to install a software that does not come with the distribution. (Realplayer for instance). Oh and how about configuring firefox and java so that you can chat? So ultimately I decided that all this is a waste of time and energy, and switched back to XP, and have …

Sulley's Boo commented: yeeeee you rock Wolfyyyyyyyy =D +2
WolfPack 491 Posting Virtuoso Team Colleague

cut it out guys. let bygones be bygones. if a particular post is helpful it is worth a lot to the person who wanted help. It is also acceptable for geeks to relax in here, and browse other forums and learning from the helpful posts in the process. If you can help you are welcome to help too. This website is for people who can teach, as well as people who want to learn.

WolfPack 491 Posting Virtuoso Team Colleague
WolfPack 491 Posting Virtuoso Team Colleague

1. Return an array from get getHoursFromUser()
2. Take a new array, say new_array and initialize it using the returned value from getHoursFromUser().
3. Pass that new_array in your function that calculates the salary.

If that is wrong can you comment on that please. Thank you .

No need to return an array because the array is a member of the class. Anything you modify in it, will be permanent. It is not necessary to pass member data to a member function also. That is the advantage of object oriented programming. Member Functions can act on Member data without explicit passing as variables.

WolfPack 491 Posting Virtuoso Team Colleague

To amano.

When you are posting bulk code, please use only [CODE][/CODE] tags. Thank you.

WolfPack 491 Posting Virtuoso Team Colleague

I haven't had much use of C/C++, but I noticed that the getHoursFromUser function has been declared as void.
Void may work differently with functions in C/C++, but a void method in Java is one which does not return a value. Is that relevant?

It is not a problem. Since the objective of the mentioned function is to get the hours worked from user input, no return value is needed. So there is nothing wrong with declaring it as void.

WolfPack 491 Posting Virtuoso Team Colleague

Post your whole code again. You must have used

#include "iostream.h"
#include "stdafx.h"

instead of

#include "stdafx.h"
#include <iostream>
using namespace std;

or

#include "stdafx.h"
#include <iostream.h>
WolfPack 491 Posting Virtuoso Team Colleague

Just put #include <iostream> after the #include "stdafx.h" line.
It would be better if you select the "Create Empty Project" option and then start from scratch. That gives you a better feel of things going on rather than using a template.

[edit] as dave said you need the using namespace std; line too. [/edit]

WolfPack 491 Posting Virtuoso Team Colleague

bah. where were you yesterday?

WolfPack 491 Posting Virtuoso Team Colleague

Yep. That is a nice trick.

WolfPack 491 Posting Virtuoso Team Colleague

I think i understand now thanks, the access of the array has to be in the same block it was initialized in? A scope thing? Is that why it won't work (says undeclared) if its accessed after the if-condition block that declared it?

Yeah. You got it. It is a scope thing.

WolfPack 491 Posting Virtuoso Team Colleague

What are these conditions? Can these conditions change while the program is running, in other words depending on user input? or just when the program is compiled? Can you give a code example? I don't think that you can change it at run-time. To change it at run-time, you should use a method like this

if ( condition 1 )
{
       Array = { initializer list 1};
       Do the processing;
       ....
}
if (condition 2)
{
        Array = { initializer list 2};
       Do the processing; // Duplicate of what the above block does. Better use a function for this part. 
       ....
}
.....

Because same code is in two places, the executable gets bulkier. If you use a function for the processing on the array, it will reduce to something like this. And the executable file size will not be significantly smaller.

if ( condition 1 )
{
       Array = { initializer list 1};
       Process_Array( Array );
}
if (condition 2)
{
        Array = { initializer list 2};
       Process_Array( Array );
}
.....

Something like this is not allowed, as you have already found out.

if ( condition 1 )
{
       Array = { initializer list 1};
}
if ( condition 2 )
 {
       Array = { initializer list 2};
}
  Do the processing;
 ....

If you only want it to change during compile time, you can use preprocessor switches.

#define CONDITION_1 1
#define CONDITION_2 0
#if  CONDITION_1 
       Array = { initializer list 1}; // This …
WolfPack 491 Posting Virtuoso Team Colleague

I can't say anything about cpp. That is not specified in the standard. It only happens in Visual C++. It may be different in gcc. But in VC++, the variable is not pushed into the stack. Only the literal it holds. In this case it is 10.

WolfPack 491 Posting Virtuoso Team Colleague

Actually the memory location for a does get modified in Visual C++. But this is implementation specific. It may not be so in gcc. But the catch is that Visual C++ never uses the value stored in a 's memory location. It is allowed to do so by the C++ standard. That is because if you declare a as const int , that means you are never going to change it's value. So as an optimization, the compiler can use the literal directly instead of the actual value stored in a . You can see this fact if you take a look at the assembly code for your program.

I have attached the assembly files in text format and line 7 is the relevant portion.


CPP Assembly

; Line 7
    push    10                  ; 0000000aH
    lea edx, DWORD PTR _a$[ebp]
    push    edx
    push    OFFSET FLAT:$SG611
    call    _printf
    add esp, 12                 ; 0000000cH

The code in red just pushes the literal 10 to the stack. Not the contents of a . So the contents of a will NOT be displayed.


C Assembly

; Line 7
    mov edx, DWORD PTR _a$[ebp]
    push    edx
    lea eax, DWORD PTR _a$[ebp]
    push    eax
    push    OFFSET FLAT:$SG795
    call    _printf
    add esp, 12                 ; 0000000cH

The code in red loads the contents of a to edx , and then pushes the contents in edx to the stack. So the contents in a will be displayed.

WolfPack 491 Posting Virtuoso Team Colleague

huh? Isn't it what?

WolfPack 491 Posting Virtuoso Team Colleague

Isn'T it obvious?

ifstream infile("data", ios::in);
        string name, surname;
        
        while (infile >> surname) {
            infile >> name;
             Person temp(infile);
Person(std::istream&);

istream and ifstream are not the same.
So the compiler does not know a proper constructor.

WolfPack 491 Posting Virtuoso Team Colleague

I think the problem is that you have declared iter as const_iterator.

map<string, Person>::const_iterator iter;

Change it to

map<string, Person>::iterator iter;
WolfPack 491 Posting Virtuoso Team Colleague

Why can't you just use the = operator?

//Accessor Function to read integer input into age variable
   int& Person::read_age(int& a)
   {
       a = age;
       return a;
   }
WolfPack 491 Posting Virtuoso Team Colleague

And I stumbled upon this tutorial also.

WolfPack 491 Posting Virtuoso Team Colleague

Use the tm structure and the mktime function to convert your date into time_t. Then you can use difftime to calculate the difference in seconds. Then convert the seconds into units that you want.

WolfPack 491 Posting Virtuoso Team Colleague

Hello Misko,
Welcome to Daniweb. I am sure fellow members will find your wide experience in the IT field very useful. Hope you make a lot of friends here.

WolfPack 491 Posting Virtuoso Team Colleague
WolfPack 491 Posting Virtuoso Team Colleague

Are you using

#include <gdiplus.h>

or

#include "gdiplus.h"

.
Have you installed the Platform SDK properly?
Have you set the Include files Directory of your compiler correctly?

WolfPack 491 Posting Virtuoso Team Colleague

Selecting "Hide Icons" does not affect the right click. It takes time for the Desktop to refresh, and after that the right click works as usual. Try pressing F5 a number of times and then right click the desktop and see. If that does not work, try restarting and right clicking. It should work.

WolfPack 491 Posting Virtuoso Team Colleague

Try

int a = b - -c;

Stop the course which asks silly questions like this.

Grunt commented: Cute Trick [Grunt] +1
Salem commented: LOL - the old favourites are the best - Salem +1
WolfPack 491 Posting Virtuoso Team Colleague

1. You have to show what you have done. We don't hand over free lunch. We only give homework help to those who show effort

2. You must post in the correct forum. This forum is intended for newcomers to say hello and introduce themselves. Most programmers don't even check this forum. I gave you the link to the correct forum (Java Forum) in my welcome message. Post your problem in that forum.

3. Use Professional English. There are no words like "tanx prob v hav devlop da frm dis hop u coild wit dis" in professional English. You may be using such words to SMS your friends, but that is not allowed here. Programmers tend to ignore posts with poor and careless English and you will not get help.

WolfPack 491 Posting Virtuoso Team Colleague

Hello Ranga.
Welcome to Daniweb. Don't worry, this is the right place to be. You will surely get a lot of help, from the Java experts in the Java forum.

WolfPack 491 Posting Virtuoso Team Colleague

wonderful In-laws

Forget the child. How do you develop this?

WolfPack 491 Posting Virtuoso Team Colleague

That means you are not linking the libraries with the object code for those functions. RTFM and find the required library.

WolfPack 491 Posting Virtuoso Team Colleague

Look for the API called FindFirstFile.

WolfPack 491 Posting Virtuoso Team Colleague

Sorry I didn't get you. I made a few changes to the code you posted, and now it is working correctly. If this comment

// pass filename to your xml file opening function

confused you, it was a leftover from the code snippet. You should open the html file after that.
Run the program and see what happens.
If you need further help be a little more descriptive.

WolfPack 491 Posting Virtuoso Team Colleague

Listen, I don't speak c++, I don't really care what you c++ rabis debate about evry day.

In school we do Pascal , Pointers don't come into play until 1st year university.

So what are you trying to tell us? If you expect C++ to behave like Pascal, you better do what you are trying to do in Pascal. Dont use C++.

If you want to learn C++, learn it right. Learn to follow advice. Otherwise you will be programming Pascal the rest of your life even though you will think you are programming in C++.

The fact that you haven't learnt pointers hasn't stopped you from playing with pointers, so either stop using pointers until your university starts pointer lessons, or try to understand why the above advice was given. Saying that you don't care about the advice given will be bad for YOU in the long run.

WolfPack 491 Posting Virtuoso Team Colleague

This code should work.

#include <iostream>
using namespace std;
int main()
{
    int epi;
    char quit;
    
    quit='N';
    while (quit !='Y' && quit!='y')
    {
         cout<<"type 1-197 to open that episode";
         cin>>epi;
         if (epi >= 1 && epi <= 197)
         {
              char filename[ 20 ] = "";
              snprintf( filename, 19, "epi%d.html", epi );
              printf("%s\n", filename );
              // pass filename to your xml file opening function
         }
         cout<<"Quit(Y/N)?";
         cin>>quit;
    }
}
WolfPack 491 Posting Virtuoso Team Colleague

Ok , but this program runs evrytime a user logs in , so evry time a user logs in , he/she has to unblock it?[/quote]

Running a chat system every time a user logs in to the computer is bad practice unless the user explicitly wants it to do so. So you should provide an option for the user to check/uncheck this feature. However if the administrator has unblocked it, the user won't have to unblock it every time he/she logs in.

Can't you unblock it once you install it, and WF will never bother you again for the rest of your life?

Windows Firewall does not block a program when you install it. It blocks a program the first time the program tries to accept an unsolicited incoming connection. But if the administrator unblocks it, it won't trouble you again. However this cannot be done at installation time. It should be done at the initial execution. In any case this is a manual process and not a programable process. All depends on whether the administrator permits the program.

WolfPack 491 Posting Virtuoso Team Colleague

I don't know about Adobe update, but Windows Firewall definitely blocks Yahoo Messenger. The same for Windows Messenger too. The administrator should unblock it.

By the way, what is the big deal? Once you unblock it once, Windows Firewall won't trouble you again.

WolfPack 491 Posting Virtuoso Team Colleague

No I don't think so. The windows firewall is external to your program. So unless you have administrative rights to unblock the port that the program needs to update itself, the Windows firewall will block it. Sometimes antivirus programs also may block certain ports.

WolfPack 491 Posting Virtuoso Team Colleague

Here is a similar code snippet. Instead of using a loop, you can get the number from the keyboard and pass that to snprintf .

WolfPack 491 Posting Virtuoso Team Colleague

yeah. it is only 100 KB.

WolfPack 491 Posting Virtuoso Team Colleague

For me uncheck all deselected the little checkboxes next to all the names of my buddies. Then you have to click the Save List button.

Okay. Is this a recoverable? or should I go back inviting them again if I did the above in mistake?

Wht error message are you seeing?

Upload of file failed.

WolfPack 491 Posting Virtuoso Team Colleague

Nope. Can't upload still.

Anyway, uncheck all does not clear my buddy list?

WolfPack 491 Posting Virtuoso Team Colleague

Is it just me or isn't this a bit dangerous option? ( Like Format C: (Y/N) ). Once you uncheck all and press save, all your contacts are gone unrecoverably? I am too chicken to press and see what happens.

Tried to upload a screenshot of this option, but couldn't upload the picture. Don't know if it was on my end. Nothing could be attached.

WolfPack 491 Posting Virtuoso Team Colleague

Something like this.
Do not use eof for end-of-file checking.

ifstream    file(filename);
string      line;
if (file)
{
    string token;
    stringstream iss;
    while ( getline(file, line) )
    {
        iss << line;
        while ( getline(iss, token, ',') )
        {
            cout << token << endl;
        }
        iss.clear();
    }
}
WolfPack 491 Posting Virtuoso Team Colleague

For chat I use WLM only. None of my friends have an AIM account, and I like the interface of WLM very much. Nobody I know chats in Google chat either. Since I don't use yahoo messenger, contacts who do are missing a lot. :cheesy:

For important email, I use either the office email account or the email address of my phone (makes checking easier and fast). All the gmail, msn, or yahoo accounts are really meant for places where I need an email account to register. For various forums with a huge quantity of emails a day, I use the gmail service obviously because of the large inbox capacity. Otherwise it would not make much difference which service I use. But since I use the WLM , I prefer the hotmail account because I get the notification of the registration email, and I am taken to the required email with a mouse click.

So my pair of choice will be "Gmail-MSN" or "hotmail-MSN"

WolfPack 491 Posting Virtuoso Team Colleague

You can either use

char filename[MAX_PATH];
    GetModuleFileName(NULL, filename, MAX_PATH);

or
the command line passed to WinMain

int WINAPI WinMain(HINSTANCE instance, HINSTANCE prev_instance, char* command_line, int show_command)
WolfPack 491 Posting Virtuoso Team Colleague

i havent made any code yet but i was wondering if i could like...
have the user select a number and have the program open the Episode 1.html doucment...

Yes you can.

WolfPack 491 Posting Virtuoso Team Colleague

any idea to to divide the string say into blocks of 4 characters?

Use std::string::substr().

WolfPack 491 Posting Virtuoso Team Colleague

Explain.
How do you get the filename that you want to open?
What is the significance of the input number and the file you want to open?
When you say open, does that mean open using a browser, or just using fstream or fopen?

WolfPack 491 Posting Virtuoso Team Colleague

Except maybe Mrs Wolfpack she's so hard to please he he :cheesy:

Tell me 'bout it. :rolleyes: