Questions tagged [main-method]

115 questions
67
votes
6 answers

Arguments to main in C

I don't know what to do! I have a great understanding of C basics. Structures, file IO, strings, etc. Everything but CLA. For some reason I cant grasp the concept. Any suggestions, help, or advice. PS I am a linux user
Anthony
  • 695
  • 1
  • 6
  • 4
49
votes
5 answers

Should I define a main method in my ruby scripts?

In python, a module doesn't have to have a main function, but it is common practice to use the following idiom: def my_main_function(): ... # some code if __name__=="__main__": # program's entry point my_main_function() I know Ruby…
MiniQuark
  • 40,659
  • 30
  • 140
  • 167
41
votes
6 answers

Is there a "main" method in Ruby like in C?

I'm new to Ruby, so apologies if this sounds really silly. I can't seem to figure out how to write a "main" code and have methods in the same file (similar to C). I end up with a "main" file which loads a seperate file that has all the methods. I…
rchn
  • 843
  • 1
  • 8
  • 10
33
votes
6 answers

Invoking Java main method with parameters from Eclipse

During development (and for debugging) it is very useful to run a Java class' public static void main(String[] argv) method directly from inside Eclipse (using the Run As context menu). Is there a similarily quick way to specify command line…
Thilo
  • 241,635
  • 91
  • 474
  • 626
18
votes
6 answers

Intellij doesn't show run button

Intellij doesn't show run button even if that file is in src folder. Maybe do you know what to do? P. s. It's strange because that file used to show run button but after recloning git repository it just doesn't show any more.
Ugnius Malūkas
  • 2,151
  • 6
  • 26
  • 37
13
votes
1 answer

TCHAR* envp[]: What is it?

I created a VC++ console project with Visual Studio and it auto-generated this function: int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { ... } I was just wondering what envp stands for and how/when I can/should use it? Thank you!
Simon
  • 8,777
  • 4
  • 35
  • 53
9
votes
1 answer

Proper use of UIApplicationMain

I have decided to load my views programmatically, so putting: int ret = UIApplicationMain(argc, argv, nil, nil); Would not work. I do have a ViewController and an AppDelegate, though. What would be the proper use of UIApplicationMain to use a…
Mohit Deshpande
  • 48,747
  • 74
  • 187
  • 247
8
votes
8 answers

legal main method signature in java

class NewClass{ public static void main(String a){ System.out.print("Hello"); } } When I'm trying to execute above code, then it shows an error, main method not found. But when I changed public static void main(String a) to public static void…
Ravi
  • 28,657
  • 41
  • 110
  • 158
7
votes
1 answer

C# console application: Main method return value VS Application.ExitCode

I am writing a console program for windows task scheduler to run. My Main() method has a return type of int and I return different numbers when exiting to indicate the result of execution, which I can access in a .BAT script as %errorlevel%. However…
Lionet Chen
  • 754
  • 7
  • 24
6
votes
8 answers

How to write main() in an OOP way?

When I first started programming, I wrote everything in main. But as I learned, I tried to do as little as possible in my main() methods. But where do you decide to give the other Class/Method the responsibility to take over the program from main()?…
Srikanth
  • 11,148
  • 20
  • 64
  • 87
5
votes
4 answers

Why can't use Void as the return type for main method

So I wanted to test Void type then I wrote this simple program : package ehsan; public class NumTest { public static Void main(String[] args) { System.out.println("Hello, World!"); return null; /* The compiler forced me to do…
user6538026
5
votes
4 answers

Using the main method of classes for debugging?

It is good practice to use the main method to test a java/.net class? I've seen it reccommended in some text books, but to me it seems like using a unit testing framework would make more sense... The main method gives you one point of entry to the…
Omar Kooheji
  • 50,943
  • 65
  • 176
  • 234
4
votes
1 answer

Java - Possible main method arguments in windows

I wondered whether there was any connection between the main method's parameter String[] args and the possibility of opening files with a specified program. Considering that I wrote a simple program that writes down every String of args, then opened…
Duke
  • 360
  • 2
  • 12
4
votes
6 answers

Inheriting the main method

I want to define a base class that defines a main method that instantiates the class, and runs a method. There are a couple of problems though. Here is the base class: public abstract class Strategy { abstract void execute(SoccerRobot robot); …
Eric
  • 87,154
  • 48
  • 211
  • 332
3
votes
4 answers

Is it worth to ensure that non-callable Python classes do not get called?

If yes, can you suggest a better way than below? Please elaborate/justify. class X: ... if __name__ == '__main__': # TODO: Should we bother doing this? errorMessage = 'This class is not meant to have a main method. Do not execute…
Hamish Grubijan
  • 9,812
  • 18
  • 89
  • 143
1
2 3 4 5 6 7 8