I want to have variable parameters for sytem command in unix

Discussion in 'Software' started by gorthi, Sep 24, 2011.

  1. gorthi

    gorthi

    Joined:
    Sep 24, 2011
    Messages:
    2
    Likes Received:
    0
    Hi! I had typed the following code in c
    main()
    {
    char dirname[15];
    char temp[50];
    printf("enter directory name: ");
    scanf("%s",dirname);
    sprintf(temp,"cd %s",dirname);
    system((char *)temp);
    }

    the programmer compiles without any error using in gcc.
    but when I run it and enter dirname it says can't cd and shows some junk value.
    All I want is a way to pass a variable to system command ! PLS HELP REALLY URGENT!!!!!!!!!!!
     
    gorthi, Sep 24, 2011
    #1
    1. Advertisements

  2. gorthi

    gorthi

    Joined:
    Sep 24, 2011
    Messages:
    2
    Likes Received:
    0
    The code works for ls command but not for cd command.The earlier error I ahve debugged but ls works but cd command doesnt!!! I cant understand why?????
     
    gorthi, Sep 24, 2011
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.