Questions tagged [main-method]

117 questions
72
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
  • 745
  • 1
  • 6
  • 4
51
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
  • 46,633
  • 36
  • 147
  • 183
46
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
  • 973
  • 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
  • 257,207
  • 101
  • 511
  • 656
29
votes
12 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,649
  • 7
  • 29
  • 42
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
  • 9,255
  • 4
  • 37
  • 54
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
  • 53,877
  • 76
  • 193
  • 251
8
votes
1 answer

How to change Main method to async in new .NET 6.0

I would like to change Main method to async, but I don't know how to edit this method, since it is "invisible" in .NET 6.0. I want it to look something like this: static async Task Main(string[] args). So how can I edit it?
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. When I changed the signature to public static void…
Ravi
  • 30,829
  • 42
  • 119
  • 173
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
  • 832
  • 11
  • 26
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,780
  • 23
  • 72
  • 92
6
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
  • 95,302
  • 53
  • 242
  • 374
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
  • 54,530
  • 68
  • 182
  • 238
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
  • 386
  • 2
  • 13
1
2 3 4 5 6 7 8