• Welcome to Valhalla Legends Archive.
 

Well...Don't be to hard on me.

Started by Bob, August 10, 2003, 01:09 PM

Previous topic - Next topic

Vamp

in one tutrial, it used
int main(void)
in everything, but also had a return value, so like whats the diffence with this one?

Yoni

Quote from: Vamp on August 23, 2003, 09:59 AM
in one tutrial, it used
int main(void)
in everything, but also had a return value, so like whats the diffence with this one?

That just means it has no parameters. This is perfectly legal.
Some valid mains:

int main()
int main(void)
int main(int argc, char *argv[])
int main(int argc, char *argv[], char *envp[])


The first two are essentially the same, and the last two are for when you need to get commandline/environment info.

Eibro

Quote from: Yoni on August 23, 2003, 11:07 AM
Quote from: Vamp on August 23, 2003, 09:59 AM
in one tutrial, it used
int main(void)
in everything, but also had a return value, so like whats the diffence with this one?

That just means it has no parameters. This is perfectly legal.
Some valid mains:

int main()
int main(void)
int main(int argc, char *argv[])
int main(int argc, char *argv[], char *envp[])


The first two are essentially the same, and the last two are for when you need to get commandline/environment info.
Also, the last one is non-standard, iirc.
Eibro of Yeti Lovers.

Yoni

Quote from: Eibro on August 23, 2003, 07:37 PM
Also, the last one is non-standard, iirc.
Eibro is correct. envp is not standard as I thought, but rather a very common extension. +1!

The standard way to get environment variables is getenv() in stdlib.h.

Bob

#19
Well It's Bob again  ;D Long time no post, But I've learned a little bit more and I was wondering if anyone could give me some sort of a "quiz program" to test what I have learned nothing to difficult--Thanks--

When I say quiz program I mean something for me to make to test my knowledge thanks again--

Adron

Make the command line application Drag that implements this function.

Start the program with a file name (wildcards allowed) as argument.


C:\Music>Drag *kylie*mp3


The mouse cursor becomes a "drag file" cursor, and you can drop the files into a msn chat window to send them to someone.

You will find the first file name in argv[1]. Allow multiple files to be dragged at once.

Post the source code here.

Dricoust

Hi,
main's return value tells the os on how the application ran,
return 0; Everything ran correct.
return 1; Dident run correct.

Using void main is acceptable by all means. Although as i have acknowledged, when void is used the os still requires the status of what happened, and since no return. It always returns 0;.
Usually when using int main() you can return the value (Ending the program) at you're own choice. ie

#include <iostream>
using namespace std;

int main()
{
char cmd[5];
cout << "Enter a number between one and 5";
cin >> cmd;
if(atoi(cmd) > 5) {
                             return 1; // Assuming the value is critical to be
                                            // between 1 & 5.
                           }
else { return 0; }
}

As to my understanding.
And you are certainly not a 'newb' by any means. Damn i had trouble with JavaScript first time i used it.
Now i have my own chat server, using VB as script =]

Refrences:
C++ From The Ground Up
MFC Programming With Visual C++.NET 2003
C++ The Complete Refrence Edition1 - 5.
Programming With DirectX9a.

Banana fanna fo fanna