Very Simple C question - reading input parameters/flags... [SOLVED]

This is an extremely simple question. Please forgive me for being a noob. I am writing an application in C (with GCC) called GAPE and need to be able to pass it parameters through a shell script (/usr/bin/gape) that can determine how it runs. To start with easy stuff, I want the end-user to be able to type "gape -V" to output the version of the program. How do I do that? I understand that I need to put the shell script in /usr/bin...where should I put the actual gcc-compiled gape application? Or do I even need a shell script? Can I just put the GAPE binary in /usr/bin and pass parameters to it directly? If so, how do I do that in C? Any help is greatly appreciated.
Last edited by tony5429 (2008-03-10 12:00:21)

include <stdio.h>
main(int argc, char *argv[])
int i;
for(i = 1; i < argc; i++) //argc = the number of arguments
printf("param nr %d: %s\n", i, argv[i]); // argv[i] contain the arguments, with 0 being the program name (anyone may correct me here)
[jaqob@p238 c++-egna]$ ./a.out 1 2 3
param nr 1: 1
param nr 2: 2
param nr 3: 3
[jaqob@p238 c++-egna]$ ./a.out -h -V -zxvf
param nr 1: -h
param nr 2: -V
param nr 3: -zxvf
A very simple program that prints the parameters
And yes, you can put the program in /usr/bin/ without a shellscript
Last edited by JaQoB (2008-03-05 18:09:34)

Similar Messages

  • Very simple jstl question

    I for the life of me have not been able to find the answer to this very simple question, googling and looking at various documentation. What is the difference between accessing properties using $ or #? Is there a difference?
    Thanks

    Read on this excellent explanation about the unified EL: http://java.sun.com/products/jsp/reference/techart/unifiedEL.html

  • Swing questions: passing inputs(parameters) betwen classes

    Hi,
    I am writing a program that needs GUI. It is very new to me. And many simple questions I couldn't find answer. Part of the reason is that I don't even know how to ask questions. So, I hope you can help me.
    First question:
    I have the application ( main program ) class, in which a 'set parameter' button should invoke another 'input' panel ( coded in a separated class, I suppose), which has a couple of test fields with labels. once numbers are put in those fields and 'OK' button is clicked, those numbers need to be returned to the main program (in the form of an 'parameter' object or an array . ) My question is how to pass those information back to the main class?
    2nd
    Somehow when I click the 'X' button in the input panel, the whole program quits. I want it behaves like a 'cancel' button. How?
    Thanks!

    1) This is more of a design issue than really a java
    question. Establishing references between the objects
    is quite simple. At some point, you must have created
    the GUI from your main program. This would be a good
    point to establish a reference:Thanks! I guess I over-thought about this issue
    >
    2) You can set for a frame the default Closing
    operation, but I don't remember the exact method
    call. See the sun tutorials for this, as well.should the default closing operation be set in the parent panel or in the child panel? currently I set the parent panel to be closed when exits, and didn't set the operation in the child.
    Thanks!
    Message was edited by:
    18wheeler

  • Very simple cfselect question

    Hi,
    I have a really noob question; what is the easiest way to
    output the values of a cfselect dropdown to a cfoutput tag on the
    same page?
    I am only interested in puting the values of the dropdown
    into the cfoutput tag when the user selects on a dropdown item .
    Thanks for your time.

    Thanks for the quick reply!
    I think what i meant to say with the code i posted is that i
    am perfectly happy with validating the form on the server AND i
    have added a submit button to my form (its just not in the code i
    posted) and the form is "in fact" validating to my CF8 server.
    However where I am stuck is that I am not sure if there is still is
    tricky server behavors or other code that i need to add to the form
    or page itself.
    In the code i posted before i still only recieve the first
    output selection regardless if the submit button is pressed the
    value of "50" always appears/reappears.
    I am still new to CF and i like it a lot but it is a little
    puzzling that for such a ultra-simple task as what im stuck with i
    hope that i dont need to write reams and reams of code to do this.
    Thank you in advance.

  • Very simple network question

    Forgive my stupidity asking this question...
    I have an iBook G4 and two Windows PCs (one W2K, one XP) all happily sharing a wi-fi network using Airport Express.
    I am about to dash out to the shops to buy a USB printer so that we can all print wirelessly, using iFelix's fab website for guidance. My incredibly dumb question is this: do I need to establish any kind of network before embarking on the printer-sharing project, or, by the very fact that we are all sharing a wi-fi network, are we already three "networked" computers??
    I don't want to share any files between the computers, just a printer. Is there anything I need to do beforehand to create a network, or are we already one??
    iBook G4   Mac OS X (10.3.9)   Window XP, Windows 2000, AirPort Express

    Sanhodo: there are reports of problems with windows sharing a printer to a wireless iBook. You should read iFelix guide to wireless printing (run a google search), it will shed some light on the subject.
    JFYI, the setup of Claudine is completely different from yours, since she will connect the printer to THE ROUTER, not to a computer --which is your case-- and therefore she will avoid the problems of windows printer sharing...

  • Very simple XML question

    1. I have a simple table with a clob to store an unlimited number of contacts as follows ....
    CREATE TABLE MY_CONTACT (USER_id NUMBER, All_Contacts SYS.XMLTYPE );
    2. I inserted 1 user with 2 contacts as follows :
    INSERT INTO MY_CONTACT
    VALUES(1, sys.XMLType.createXML('<?xml version="1.0"?>
    <CONTACT>
    <CONTACTID ID="1">
    <FNAME>John</FNAME>
    <MI>J</MI>
    <LNAME>Doe</LNAME>
    <RELATIONSHIP> </RELATIONSHIP>
    <ADDRESS>
    <STREET>1033, Main Street</STREET>
    <CITY>Boston</CITY>
    <STATE>MA</STATE>
    <ZIPCODE>02118</ZIPCODE>
    </ADDRESS>
    </CONTACTID>
    <CONTACTID ID="2">
    <FNAME>Carl</FNAME>
    <MI>J</MI>
    <LNAME>Davis</LNAME>
    <RELATIONSHIP>Son</RELATIONSHIP>
    <ADDRESS>
    <STREET>1033, Main Street</STREET>
    <CITY>San Francisco</CITY>
    <STATE>CA</STATE>
    <ZIPCODE>06456</ZIPCODE>
    </ADDRESS>
    </CONTACTID>
    </CONTACT>'));
    --- 1 row inserted .
    I have the the following issues :
    3. When I run the following :
    select A.All_Contacts.extract('/CONTACT/CONTACTID/@ID').getnumberval() ID,
    A.All_Contacts.extract('/CONTACT/CONTACTID/FNAME/text()').getstringval() FNAME,
    A.All_Contacts.extract('/CONTACT/CONTACTID/LNAME/text()').getstringval() LNAME
    from MY_CONTACT A ;
    I was hoping this query would return :
    ID FNAME
    1 John
    2 Carl
    But instead, I am getting : .... How do I fix the query to get the results I am looking for ( above) ?
    ID FNAME
    12 JohnCarl
    4. I have another query :
    select A.All_Contacts.extract('/CONTACT/CONTACTID/@ID').getnumberval() ID,
    A.All_Contacts.extract('/CONTACT/CONTACTID/FNAME/text()').getstringval() FNAME,
    A.All_Contacts.extract('/CONTACT/CONTACTID/LNAME/text()').getstringval() LNAME
    from MY_CONTACT A
    where
    A.All_Contacts.extract('/CONTACT/CONTACTID/@ID').getstringval() = 1;
    that returns no rows at all !!!
    How do I get the query to return only the first set of values for CONTACTID ID=1 ? :
    ID FNAME
    1 John
    I hope this is easy to fix - my aim is to store up to ten contacts in the clob, but I cant't even get it to work with just 2 contacts ...
    Any help would be greatly appreciated.
    Thanks !!!

    If you are on 10g (I think at least 10.2.x.x) or greater, then you can also use the following. I prefer XMLTable over the table(xmlsequence()) structure.
    SELECT cid, fname, lname
      FROM MY_CONTACT A,
           XMLTABLE('CONTACT/CONTACTID'
                    PASSING A.All_contacts
                    COLUMNS
                    cid    NUMBER PATH '@ID',
                    fname  VARCHAR2(20) PATH 'FNAME',
                    lname  VARCHAR2(20) PATH 'LNAME')
    WHERE cid = 1;
          

  • Very Simple Numbers Question

    Hi all,
    I am recently converted from the PC world...
    I am trying to create a simple line graph in numbers. I have a data set that consists of about a dozen columns containing summary data from 1955 - 2007. The first column 'A' contains the year, and all subsequent columns contain the yearly variable value.
    I am trying to creat a simple line graph of each variable from year to year (i.e the first column, year, is my horizontal (x) axis, and what ever other variable -or column- is my verticle (y) axis.
    I have done this (and am doing this) quite easily in excel, but I have spend the better part of an evening trying to figure it out in numbers ('08 or '09).
    I looked at the online manuals and tutorials, but they were of no help.
    Any assistance will be most welcome.
    Many Thanks,
    Bryan

    Select the cells with dates and totals > Toolbar > Chart > Line chart > the table will have the axis the wrong way around for what you want so click the black box on the table with III on to change it to ☰.
    Open Inspector > Chart to set up the chart the way you want.
    The User Guide is available under Help on the Numbers Menu Bar,
    S.

  • Very simple Parameter question in Eclipse

    I simply want to create a report where a user can pick a date range at runtime.  I designed a simple report, added parameter fields and ran it in the designer.  It prompted me for dates and I filled them in.  The report ran in the designer just fine.  When I publish the report to the Apache Tomcat web site, I want the prompts to pop up for the user so they can pick the date range.  There are no parameters that pop up and the parameter panel shows NO parameters.  Can someone point me to a document or process that will allow me to prompt the user for these dates?  I am invoking the report from the JSP that is generated by the plugin.

    Are you passing paramete values in your code? If you do not then it will automatically asks for parameters.
    Regards,
    Tejaswini

  • Very simple Strings Question

    Hi All:
    I am stuck with a small situation, I would appreciate if someone can help me with that. I have 2 strings:
    String 1 - "abc"
    String 2 - "I want to check if abc is in the middle"
    How can I check if the string 1 "abc" is in the middle of the string 2. I mean the String 2 does not start with "abc" and it does not end with "abc", I want to check if it is somewhere between the string.
    Thanks,
    Kunal

    int i = s2.indexOf(s1);
    if((i > 0) && ((i + s1.length()) < s2.length())) {
       // somewhere in the middle
    } else if(i == 0) {
       // start
    } else if((i + s1.length()) == s2.length()) {
       // end
    } else if(i == -1) {
       // nowhere
    }

  • Very simple Hashtable question

    Ok, this might be a very dumb one, but I can't spot the error. After seeing numerous examples of a hashtable, I tried the following:
    Hashtable p = new Hashtable();
    p.put ("Alberta", "ab");
    But I keep getting the following error:
    <identifier> expected
    p.put ("Alberta", "ab");
    Can anyone tell me what I'm doing wrong???

    It's not a problem with hashtables, specificly. you can't add elements to an hash or a vector or perform another routine outside a method or a constructor. there is no way that
    that operation can be executed during compiling.
    regards

  • Very simple connection question

    New user here - about to begin learning how to use Logic Studio. I'm working on a MacBook Pro and would like to know how I'd go about being able to connect a synth, or mini disc etc. with it's stereo phono outputs, to my laptop. I'd need some kind of interface. Can anyone suggest something?

    Thanks. I'll be using a Korg Triton, and just now and then I may have that with me without my laptop, so may create stuff on it using it's own sequencer that I then want to play/record into Logic when I can, to do further work on it. I bought an Edirol UA-25 interface the other day - yet to plug it all in, but I guess that's gonna do that job?

  • A very simple voicemail question - please help!

    Hi
    My iphone 3G cuts into voicemail after only 3 rings, which isn't enough time to get it out of my pocket let alone answer!!
    How do I lengthen the amount of rings before it goes to voicemail. I've tried everything (seemingly) and there doesn't seem to be any voicemail settings anywhere on the phone.
    Many thanks

    This is controlled by your carrier, not the phone. Most carriers have a max of about 30 seconds they can set before going to voicemail. Call your carrier and ask them to extend the time to voicemail.

  • One very simple quick question please

    I am needing to admin one computer from remote sites. As the admin computer will have different IP addresses each time I work, I don't imagine this will be a problem. However, which IP address should I use for the one client. The client machine is connecting through Qwest DSL, and has an external IP and a local IP. When I use the admin computer at the same location as the client, the external IP match and the local IP are different. How do I get to the correct machine when I am imagining that all of the Qwest DSL connected computers on the same node will have the same external IP. Can I "stack" IP's? - e.g. 123.111.11.182, 222.222.222.255 ?
    Thanks in advance for all of your help.
    Al

    Normally you use the externally-facing IP address Qwest will assign to the modem, or the IP address the router picks up if a router is in use. If a router is in use, you may also have to open the appropriate ports for ARD and forward them to the client's internal IP address.

  • Very simple html5 quiz runs very slow on android 4

    I created a very simple 10 question, no pictures, no transitions, and no audio (which I can't get to work anyway when exported as html5 for android) html5 app built with phonegap.  I tried everything that was suggested by other developers, and I can't get a simple quiz to run even with a poor framerate.   I get about 5 to 10 fps. 
    Has anybody successfully built an APP that runs OK on Androids running KitKat?
    Thanks

    I'd recommend profiling the application with Adobe Scout to see what's going on, then optimizing based on those results.
    http://gaming.adobe.com/technologies/scout/

  • [Haskell]How to read in haskell and solve simple problems

    Hello,
    I'm an experienced C/C++ programmer and I would like to use Haskell to solve some problems.
    But it is hard to me to write a simple way to read input from a file and analyze it, so I ask you how to do this. I didn't find how to do this around google or this forum, that's why I came to here.
    Suppose we are given this problem:
    "We're analyzing numbers and we want to know which numbers are even. The input consists on a number, N, and then N lines which contain a single integer. You are to say what numbers are even."
    INPUT EXAMPLE:
    3
    1234
    5555555
    123044390581349287182
    OUTPUT EXAMPLE:
    yes
    no
    yes
    I wrote the module that returns a string depending on if the number is even or not... But I would like to know how to repeat that function for N numbers. I don't want a superoptimized way or a strange way, I just want a simple and readable one...
    In C++ i would do:
    for (int i = 0; i < cases; i++)
    cin >> number;
    cout << analyze(number) << endl; // analyze returns a string
    Can you iluminate with your knowledge, archers?
    Thank you.

    Well, you said that the first line has the number N, followed by N lines. Given your description the program would always test the whole file.
    If you have a file with X lines and you'd only like to test N <= X  lines, this should do it:
    module Main where
    import System.IO
    import Control.Applicative
    main = do
    let test x = if even (read x) then "yes" else "no"
    withFile "test" ReadMode $ \handle -> do
    nlines <- read <$> hGetLine handle
    content <- hGetContents handle
    mapM_ ( putStrLn . test )
    . take nlines
    . lines
    $ content

Maybe you are looking for

  • How Do I download iTunes music to a single network location share?

    i am a network administrator for my church and want to consolidate the music library to one single library that resides on our file server.  I don't want users to waste time downloading a song that we already have downloaded with the church account. 

  • Finder is gone - how do I get it back?

    After installing a recent system update my finder disappeared also everything on my desktop. The files are still there (can be accessed through Word, Excel, etc) but it's blank. Don't even have an apple menu available unless I'm running an applicatio

  • Type Casting and Truncating

    I need to have the use input a double amount such as 11.56 and then output the number of dollar bills and coins; such as the nubmer of quarters, dimes, nickles and pennies. I was able to get as far as outputting to console the dollars, but how do I g

  • Getting "Must declare the scalar variable" Error

    Hello All, I have write following query to block invoice which has Prices not equal to PriceList as below. -- To Block Invoices which has Prices not equal to PriceList IF (@transaction_type='A' OR @transaction_type = 'U') AND CAST(@OBJECT_TYPE = '18'

  • Chart with Navigation Target not working propertly

    Hi All, I have a question regarding charts with navigation targets. I have a simple report with these 3 columns: QUARTER | REGION | SALES And I want to click on sales, and see the sales detail by the region and the quarter on the line I clicked. This