Help with c++!!!!

Discussion in 'iOS Development' started by Gatzy118, Aug 11, 2008.

  1. Gatzy118

    Gatzy118 New Member

    Joined:
    Jan 7, 2008
    Messages:
    350
    Likes Received:
    0
    Device:
    iPod touch
    Hi, ive written this in c++ and i didn't know if i am using the arguments correctly? If i am then why am i getting an error that says this when i compile: Lvalue required in function main(int,char * *)

    this is the code i have got:

    Code:
    #include <iostream>
    using namespace std;
    
    void cyd()
    {
    cout << "chose cydia all";
    }
    
    
    void inst()
    {
    cout << "chose installer all";
    }
    
    
    void instcyd()
    {
    cout << "chose installer and cydia all";
    }
    
    
    void cydcust()
    {
    cout << "chose cydia only";
    }
    
    void instcust()
    {
    cout << "chose installer only";
    }
    
    
    void instcydcust()
    {
    cout << "chose installer and cydia only";
    }
    
    
    int main(int argc, char *argv[])
    {
    
    
    
    if (argc != 2 || 3 || 4)
    {
    cout << "Usage: " << argv[0] << " [c or i for packages], [o for only custom]";
    }
    
    if (argc == 2 && argv[1] == "i")
    	inst();
    
    else if (argc == 2 && argv[1] = "c")
    	cyd();
    
    else if (argc == 3 && argv[1] == "i" && argv[2] == "c")
    	instcyd();
    
    
    else if (argc == 3 && argv[1] == "i" && argv[2] == "o")
    	instcust();
    
    else if (argc == 3 && argv[1] == "c" && argv[2] == "o")
    	cydcust();
    
    else if (argc == 4 && argv[1] == "i" && argv[2] == "c" && argv[3] == "o")
    	instcydcust();
    else
    cout << "error has occured";
    
    
    
    return 0;
    }
    
    thanks everyone, i know this is the wrong forum but i think someone may still be able t help.
  2. oioioi

    oioioi New Member

    Joined:
    Apr 18, 2008
    Messages:
    102
    Likes Received:
    0
    I am not sure, have you tried to use 'c' instead of "c" in the if statments, or is that only in switches?
  3. Gatzy118

    Gatzy118 New Member

    Joined:
    Jan 7, 2008
    Messages:
    350
    Likes Received:
    0
    Device:
    iPod touch
    that shouldnt make a differen e i dont think, do you know if im using the arguments correctly, i think its the way ive used them that is givong me the lvalue error
  4. oioioi

    oioioi New Member

    Joined:
    Apr 18, 2008
    Messages:
    102
    Likes Received:
    0
    I don't konw much about argc and *argv[] but i think the
    if (argc != 2 || 3 || 4)
    should be written like this
    if (argc != 2 || argc != 3 || argc != 4)
    but I am not sure
  5. Spreche

    Spreche Member

    Joined:
    Dec 27, 2007
    Messages:
    164
    Likes Received:
    0
    Device:
    iPhone
    I thought in c and c++ theres usually supposed to be a 'int main' function. But what are you writing this for? iPhone app or a terminal app?
  6. Gatzy118

    Gatzy118 New Member

    Joined:
    Jan 7, 2008
    Messages:
    350
    Likes Received:
    0
    Device:
    iPod touch
    There is an int main function, its below the other functions. No this is for my two click jailbreak gui. Im remaking it so its simpler for me to impliment iphone support to the gui
    ------------------double post merged------------------
    Sorry, its for windows. this isn't the gui, this is an exe that gets arguments passed to it from the gui.

    http://www.ifans.com/forums/showthread.php?t=88649
  7. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    While not the way I would have done this, I did find your mistake.

    Code:
    else if (argc == 2 && argv[1] = "c")
    	cyd();
    
    Should be
    Code:
    else if (argc == 2 && argv[1] == "c")
    	cyd();
    

    EDIT: By the way, you still have some work to do, but I think this might eb a good place to start researching program arguments:
    http://publications.gbdirect.co.uk/c_book/chapter10/arguments_to_main.html



    EDIT: Oh yeah, here's the output you'll get:

    Please Register or Log in to view images

  8. Gatzy118

    Gatzy118 New Member

    Joined:
    Jan 7, 2008
    Messages:
    350
    Likes Received:
    0
    Device:
    iPod touch
    yes thankyou, I did have that problem when I managed to compile it before. I just don't understand how to retrieve the arguments that have been passed, I will have a look at the link you gave to see if that helps. Thanks, as you can tell I'm quite new to c++ and programming in general
    ------------------double post merged------------------
    btw, this isn't meant for other users so it doesn't need to be simple, I'm coding this into a GUI so I can pass arguments to this depending on options selected in the GUI so only I need to understand hehe

Share This Page