Main function in c programming

I searched the net regarding my question.  I continue to play with C off and on over the years, but now I aim to really work my way through the K&R book.
In the book one sees:
main()
hello world stuff stuff
This used to be no issue at all. It would compile and make a.out with no warning, nor complaint. Now I am working through the K&R book because I want to. I also have the first edition of Mark's Learn C on the Mac, but given how old it, and the second edition is, with regard to Xcode, I'll just stay with the terminal, BBEdit and K&R. By the way, I also saw numerous 1 star ratings on the Learn C book on amazon. Perhaps folks here could tell me how they feel about that book if they have used it and in particular the negative.
Now I get this warning, and I wonder why main has to have a type; what changed? Some new standard, the mac compiler. Now although I get the warning, default to int and all that, the compiler still creates a.out and it runs fine with the old ./a.out line command.
kr1.c:3:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]
main()
^~~~
1 warning generated.

Why not just use a properly defined main function? This avoids having the compiler guess about about the intended return type and the number and types of the inputs. The C99 version of Standard C permits the two versions below:
int main(void) {...}
int main(int argc, char *arg[]) {...}
See http://en.wikipedia.org/wiki/Entry_point#C_and_C.2B.2B for more details, and OS specific main variants.
The last (2:nd) edition of K&R (http://en.wikipedia.org/wiki/The_C_Programming_Language) was released in 1988 preceding standard (ANSI) C and its C89, C95, C99 and C11 variants (http://en.wikipedia.org/wiki/ANSI_C) so K&R is at the very least somewhat out of date with modern C.

Similar Messages

  • Functionality of main function

    Hello there:
    what's the functionality of main function in a program?
    This is a question asked in an interview. The answer on my mind is, main function is the entry for a program to start running.
    Any more addtional and completed explainations?
    Thanks,
    sway

    Any more addtional and completed explainations?The correct reply is to stand up, politely say that enought is enought, and then proudly leave the room without looking back. -:)

  • What is the main functionality of FM 'ISU_S_PAYSCHEME_ROLLIN_ROLLOUT' ?

    Hi Folks,
      I need to use the function module 'ISU_S_PAYSCHEME_ROLLIN_ROLLOUT'. what is the main functionality of this function module? there is no documentation available for this FM.
    Thanks in advance

    Hi,
    Plz follow the link below for answer of your question.
    Link is: Re: how to call standard SAP method in the Custom Program ?
    Thanks & Regards,
    Sarita Singh Rathour

  • Main function theory question

    Hello,
    Java is said to be pure object oriented.
    In order to make an executable program, one must provide a main function in the class of execution.
    This behavior is not pure object oriented.
    why couldnt a program start running by executing the constractor of the main class?
    if you think this question is posted in the wrong forum, plz notify me where should i post it.

    The main method also exists for practical reasons. How else would the JVM pass command-line parameters to your program? Either you require that a class has a static main, or you require that it has a constructor that accepts an array of Strings. But what if your class requires a constructor with an array of Strings as it's only parameter? How does Java know that this isn't an entry point to the program? The static main therefore acts as a clear entry point, whereas constructors do not.
    I've never used Eiffel, but I have a tough time imagining how you could start a program from anything but a static context. Even if you started from a Constructor, it just means that the RT is creating a static context for you under the hood from which it is calling your constructor. This way, you at least have control over the context you are using.

  • What are the main parts in ABAP Programing to work in Real Time ?

    Hi
    I would like to know hat are the main/important parts in ABAP Programing to work in real time environment.
    Moderator message : Search for available information. Thread locked.
    Edited by: Vinod Kumar on Aug 1, 2011 9:50 AM

    Hi Ashok,
    There are so many programming parts such as Function modules, report programs, workflows, smartforms, webdynpro, adobe forms, scripts etc.
    In which context you want answer can you please tell ?
    Regards,
    Aabha

  • How to add a code TestIfElse(10) to the Main method of the Program.cs class?

    How to add a code  TestIfElse(10) to the Main method of the Program.cs class?
    Here is my code and I have copied from the Wiley book for Microsoft certification page 14,
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ifelse_Statement
        class Program
            static void Main(string[] args);
            TestIfElse(10);
            public static void TestIfElse(int n);
            if(n < 10)
                     Console.WriteLine("n is less than 10");
             else if(n < 20)
                    Console.WriteLine("n is less than 20");
             else if(n < 30)
                Console. WriteLine("n is greater than or equal to 30");
    Here is the error list I am getting,
    Error 1      Method must have a return type        C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 13
    switch_Statement
    Error 2
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 24
    switch_Statement
    Error 3
    Method must have a return type C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 9
    ifelse_Statement
    Error 4
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 20
    ifelse_Statement
    Error 5
    Invalid token 'if' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 9
    ifelse_Statement
    Error 6
    Invalid token '10' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 7
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 8
    Invalid token '(' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    18 35
    ifelse_Statement
    Error 9
    A namespace cannot directly contain members such as fields or methods
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    20 10
    ifelse_Statement
    Error 10
    Type or namespace definition, or end-of-file expected
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    30 1
    ifelse_Statement
    Error 11
    The type or namespace name 'n' could not be found (are you missing a using directive or an assembly reference?)
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    16 12
    ifelse_Statement
    Error 12
    'System.Console.WriteLine(string, params object[])' is a 'method' but is used like a 'type'
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    18 26
    ifelse_Statement

    static void Main(string[] args){
    TestIfElse(10);
    public static void TestIfElse(int n)
    if (n < 10)
    Console.WriteLine("n is less than 10");
    else if (n < 20)
    Console.WriteLine("n is less than 20");
    else if (n < 30)
    Console.WriteLine("n is greater than or equal to 30");
    Fouad Roumieh

  • Drag and drop not working.  When trying to move a cell or icon the shadow of the cell or icon being moved appears under the cursor but can't be released causing a freeze of function within the program.  Happens in finder numbers and firefox

    Drag and drop not working.  When trying to move a cell or icon the shadow of the cell or icon being moved appears under the cursor but can't be released causing a freeze of function within the program.  Happens in finder numbers, firefox, and when trying to move any file from the downloads folder.
    This is a serious pain.
    Please help.
    WB

    Yes, all I can tell you is that Finder does not have that function in ML. Your system is "working as expected".
    You can file feedback here.

  • Attempting to add aditional functionality to my program. Can it be done?

    I play online poker. I've written a program that keeps track of poker hands I've played, as well as the players I've played against. After every hand, the poker client writes the hand to a text file. My program reads these text files, extracts certain information regarding the hands and stores it in a database.
    I want to add the functionality to the program that would enable it to be aware of things that are happening during the course of a hand; i.e, what cards are displayed on the board, what action each player has taken (raise, bet, check, etc.), how much each player bets, etc. These things can easily be attained AFTER the hand is over by reading through the text file that is saved, but I want the program to have access to this information DURING the hand, so I can have it preform various calculations and various other tasks.
    Now, I'm not sure how to go about doing this, nor am I sure if this can even be done in java. I expect what I would need to do is have the program intercept the data which represents various things - actions taken by players, bet sizes, displayed cards, etc - that is transfered between the poker client and server . Or, perhaps, there is a simpler, more obvious solution to this.
    So, is there any way to do the above with the proposed solution? If not, is there any other way that my program can work with the poker client itself in order to obtain the desired information without dealing with the interaction between the poker client and server?

    Who does this and how? Is the progam dumping this information? Are you manually entering it? Or did you actually write a program that is doing this? And how does it work?What happens is after a hand is completed, the poker client writes the hand to a text file. My program reads through this text file and extracts certain information. So, the text file looks something like this:
    Seat 4: player 1 ($156.50 in chips)
    Seat 6: player 2 ($17.50 in chips)
    player 1: posts small blind $1
    player 2: posts big blind $2
    *** HOLE CARDS ***
    Dealt to player 1 [9s Js]
    player 1: raises $2 to $4
    player 2: raises $2 to $6
    player 1: calls $2
    *** FLOP *** [3d As Jh]
    player 2: bets $2
    player 1: calls $2
    *** TURN *** [3d As Jh] [3h]
    player 2: bets $4
    player 1: raises $4 to $8
    player 2: calls $4
    *** RIVER *** [3d As Jh 3h] [6s]
    player 2: bets $4
    player 1: calls $4
    *** SHOW DOWN ***
    player 2: shows [Ah Kd] (two pair, Aces and Threes)
    player 1: mucks hand
    player 2 collected $39 from pot
    *** SUMMARY ***
    Total pot $41 | Rake $2
    Board [3d As Jh 3h 6s]
    Seat 3: player 2(big blind) showed [Ah Kd] and won ($39) with two pair, Aces and Threes
    Seat 4: player 1 mucked [9s Js]
    So my program just parses this text and extracts certain information, then saves it to a database I created using JDBC. I can then access this info through the GUI I created.
    This question is problematic because I don't see how if you actually wrote a program that actually does something that you couldn't make it working during the game and not just after. What I suspect is happening is that either the client is dumping this information for you or that you are manually capturing it.
    So can you describe how you are getting the information now exactly?The problem is that the text file is written to AFTER the hand takes place, not during. I'm looking for a way to access what is taking place in the hand, during the hand and not after.
    Is that helfpul at all?

  • Could not find the main class: SearchExcel.  Program will exit.  ????

    sekic0429{uabudd_milou}[w10/rbssw/2.0] pwd
    /tmp/MyJava/jexcelapi
    sekic0429{uabudd_milou}[w10/rbssw/2.0] printenv CLASSPATH
    /tmp/MyJava/excelapi:/app/jdk/1.6.0_16/jre/lib:/app/jdk/1.6.0_16/lib
    sekic0429{uabudd_milou}[w10/rbssw/2.0] ls
    build ExcelSearch.java index.html resources SearchExcel.java~ tutorial.html
    docs ExelSearch.java~ jxl.jar SearchExcel.class src workbook.dtd
    ExcelSearch.class formatworkbook.dtd jxlrwtest.xls SearchExcel.java TestSpecification.xls
    sekic0429{uabudd_milou}[w10/rbssw/2.0] javac -extdirs . ExcelSearch.java
    sekic0429{uabudd_milou}[w10/rbssw/2.0]
    sekic0429{uabudd_milou}[w10/rbssw/2.0] java ExcelSearch
    Exception in thread "main" java.lang.NoClassDefFoundError: ExcelSearch
    Caused by: java.lang.ClassNotFoundException: ExcelSearch
    at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: ExcelSearch. Program will exit.
    sekic0429{uabudd_milou}[w10/rbssw/2.0] cat ExcelSearch.java
    import java.io.File;
    import java.io.IOException;
    import java.util.Date;
    import jxl.*;
    import jxl.read.biff.BiffException;
    public class ExcelSearch
    public static void main(String[] args)
    try
    Workbook workbook = Workbook.getWorkbook(new File("TestSpecification.xls"));
    catch (IOException e)
    e.printStackTrace();
    catch (BiffException e)
    e.printStackTrace();
    Regards Peter, hope for answer

    r035198x wrote:
    Where is SearchExcel.class?Excellent question, though I think I spotted a problem with the cp supplied.
    Note the documentation for -cp state (in part)
    For example, if directory foo contains a.jar and b.JAR, then the class path element foo/* is expanded to a A.jar:b.JAR, except that the order of jar files is unspecified.So instead of this..
    java -cp /tmp/MyJava/excelapi:/app/jdk/1.6.0_16/jre/lib:/app/jdk/1.6.0_16/lib SearchExcel..try this..
    java -cp /tmp/MyJava/excelapi/*:/app/jdk/1.6.0_16/jre/lib:/app/jdk/1.6.0_16/lib SearchExcelNotes:
    1) Adding the JRE classes to the classpath should not be necessary, but I left the rest of the cp unaltered to highlight the one specific difference I am suggesting.
    2) When posting code, code snippets, HTML/XML or input/output, please use the code tags. The code tags help retain the indentation and formatting of the sample. To use them, select the sample text and click the CODE button.
    If that still fails, tell us more specifically where the SearchExcel class is by copy/pasting the output (within code tags) of the command..
    prompt>jar -tvf mysearchexcel.jarWhere, of course, you replace 'mysearchexcel.jar' with the actual Jar name it is supposed to be located in.
    Edit 1:
    Changed JavaDocs -> documentation.
    Edited by: AndrewThompson64 on Jan 11, 2010 7:12 PM

  • Does ExtendScript have a concept of "main" function/method like when script is included as a library

    I was just wondering whether ExtendScript has any concept like a main method, whereby if the current script is included by another script like a library import it will not execute this main function/method and only execute it when the script is run directly.
    Similar to Java's main() method and Python's __main__.
    If not, is there a workaround to mimic such behavior generically?

    I cannot reproduce this.  Can you create a very simple repro of this issue and post to OneDrive?
    Jeff Sanders (MSFT)
    @jsandersrocks - Windows Store Developer Solutions
    @WSDevSol
    Getting Started With Windows Azure Mobile Services development?
    Click here
    Getting Started With Windows Phone or Store app development?
    Click here
    My Team Blog: Windows Store & Phone Developer Solutions
    My Blog: Http Client Protocol Issues (and other fun stuff I support)

  • How to pass argument in main function ?

    How to pass arguments in main function of one class from another class ?
    I don't want to pass argument from command prompt.
    I want to try something like this -
    class Test{
    public static void main(String args[]){
    for(int i=0;i<args.length;i++)
         System.out.println(args);
    class Fun{
    public static void main(String args[]){
         Test t=new Test("Hello","good bye");
    when i run Fun class it gives error.
    Suggest me how can i do that.

    In Fun class main method does not take arguments that is fine. In Test class instead of main method you can have constructor to take input parameters as suggested by BalusC
    However, if you want to make your existing code work, you can call (though not appropriate) main() method of Test class from main() method of Fun class (As main() method is static object is not required to invoke this):
    Test.main(new String[]{"Hello","good bye"});Here is your code:
    class Test{
    public static void main(String args[]){
    for(int i=0;i<args.length;i++)
    System.out.println(args);
    public class Fun{
    public static void main(String args[]){
    //Test t=new Test("Hello","good bye");
    Test.main(new String[]{"Hello","good bye"});
    } Thanks,
    Mrityunjoy                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Help with main function

    Can someone help me out with this? Im trying to create a main function out of this contructor.
    public studentID()
    int size; //hold returned values from box
    int id;
    int age;
    size = Integer.parseInt(JOptionPane.showInputDialog (" Enter a nummber between 1 & 40")); //dialog box
    recCount = 0;
    idArray = new int[size];
    ageArray = new int[size];
    for(int i = 0; i <size; i++) //ask for values (size) times
    id =
    Integer.parseInt(JOptionPane.showInputDialog ("Enter an ID Number"));
    age =
    Integer.parseInt(JOptionPane.showInputDialog ("Enter an age"));
    inputStudent(age, id); //calles method to put values in array
    displayAll();
    selectionSort(idArray, ageArray, size);
    newNumberTable();
    selectionSort(ageArray, idArray, size);
    newAgeTable();
    }

    So what's the problem? Dump it all into the main method.
    Actually I'd advise thinking carefully about whether it should really be in main(). Generally, IMHO, main should only bootstap an app. The real functionality should be in other methods that main() calls.

  • Do we have standard function module or program to activate transformation?

    Hi Gurus,
    Do we have any standard function module or program to activate transformation in BI system? If yes please let me know or let me know how to proceed with to create custom program to activate transformation.
    Thanks,
    Manoj

    Hi Sven,
      Thanks for your help.
    Even I am facing the same problem, we didnt want to open the production system to activate the transformation also it take time to transport them every time from development
    can you please explain how to use these methods, what parameters to pass
    do you have a sample code, it will be of great help.
    use this methods
    cl_rstran_trfn=>factory
    cl_rsds_rsds=>if_rso_tlogo_general~get_instance
    l_rsds->if_rso_tlogo_maintain~is_active
    l_rsds->if_rso_tlogo_maintain~activate

  • Function Module or Program to get where used list

    Hi,
    I´ve been searching for Function Module or program to get where used list for an object.
    I try using the FM 'RS_TOOL_ACCESS' with parameters operation = 'CROSSREF', objectname = 'ZMYPROG', object_type = 'PROG'
    and in effect i get the list of object where the program is used, but the list is showed in standard screen.
    is there a function or program to obtain the used list for an object but in an internal table?
    I'm using version 4.6B.
    I checked the function module RS_INFOSYSTEM_CREATE_REQUEST, but i didn't obtain any result, is there a funcion or combination or FM to get the used list?
    thanks,
    Alejandro
    Message was edited by: Alejandro López

    Hi Alejandro,
    Please check this sample program.
    DATA: OBJTYPE TYPE  EUOBJ-ID.
    DATA: OBJECTS TYPE RINFOOBJ.
    APPEND P_OBJECT_NAME TO OBJECTS.
    OBJTYPE = P_OBJECT_TYPE.
    CALL FUNCTION 'RS_INFOSYSTEM_CREATE_REQUEST'
      EXPORTING
        OBJTYPE            = OBJTYPE
        ACTION             = SWBM_C_OP_WHERE_USED_LIST
      IMPORTING
        INFOSYSTEM_REQUEST = P_WB_REQUEST
      TABLES
        OBJLIST            = OBJECTS
        DEVCLASS           = p_scope_devclass
        OBJKEY             = p_scope_objkey
        I_SCOPE_OBJECT_CLS = P_SCOPE_OBJECT_TYPES
        I_SCOPE_OBJECTS    = P_SCOPE_OBJECTS
        EDITOR_SOURCE      = P_EDITOR_SOURCE
      EXCEPTIONS
        NOT_EXECUTED       = 1
        BATCH              = 2
        OTHERS             = 3.
    Hope this will help.
    Regards,
    Ferry Lianto
    Please reward points if helpful.

  • Update TVARV table entries using a Function Module or Program

    Hi Gurus,
    My requirement is that I have a entry in TVARV table which has a 'low'. We would like to change this value whenever we desire. We are unable to do it via sm30 and se16 as table maintenance access is not permitted in Production environment.
    Can you please provide any Function module or program code to do it?
    Requirement - User can enter a value into TVARV table by executing a function module or program
    Thank you all, will award points,
    Priyansh

    Hi Priyansh,
    Please refer to SAP Help for more information on variant maintenance and more specifically variable values in variants. You can use t/code STVARV for maintaining the variant variables in table TVARVC (Client-Specific Variant Variables).
    Note: I suggest to use the TVARVC table instead of TVARV.
    If you are looking for Function Modules in the area of Variant Maintenance, then please have a look at Function Group SVAR (t/code SE80).
    If you are looking for Function Modules in the area of User Variables in Variants, then please have a look at Function Group SVUV (t/code SE80).
    Furthermore, if you are looking for a program to update table TVARVC, please have a look at ABAP: Dynamic Variant Processing with STVARV.
    Best eregards,
    Sander

Maybe you are looking for

  • The dealer changed our plan without letting us know about disadvantage.

    An authorized dealer changed our plan without letting us know what is going to be changed, and we didn't even know they are changing our plan on new contract, we just found out, they do not want to answer. I want to know if we can get back our old pl

  • Error Message: Not Supported Method

    I have been trying to access my email via Verizon.net all day and get the following error message: Not Supported Method. Does anyone have any insight???? Thanks.  Solved! Go to Solution.

  • Iview performance and rendering

    Hi guys, I have portal running Transactional iView for su01 http://server:50000/irj/servlet/prt/portal/prtroot/pcd!3aportal_content!2fcom.company.company!2fcom.company.iViews!2fSU0- Once opened I get the error in I.E. 11 The IE compatibility view is

  • Transfering file from one system to another

    Hi, Is there any mean by which we can transfer file from one system to another without programing??? Thanks and best Regards. Kusum.

  • Adobe Reader plugin

    When I installed Adobe reader 8, it became my default pdf plugin in Safari (instead of Preview). Now pdfs take about 10 times as long to display. How do I undo this unwanted intrusion on my life? I can't find anything in the safari or Reader settings