C question

Vlad shiwan-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Thu Jul 20 17:58:20 UTC 2006


        First, you use char arrays to store your strings; C has no
inherent String type:

char command[256];

        Then, print your args or whatever into a buffer, with sprintf():

sprintf(command, "stuff", command, etc);

        Then, you can do something like a system() call:

system(command);

        I haven't done C in a long, long, long time. Concordantly, YMMV. :)


        -- Vlad

On 7/20/06, Madison Kelly <linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org> wrote:
> Hi all,
>
>   As something of a follow-up to my last question, I need some C help
> (a language I am quite 'n00by' in :p ).
>
>   What I want to do is, I think, simple. Take a set of command line
> options and use them when calling a perl script. From the ANSI C book I
> have gotten to the point where I can print the commands to STDOUT but I
> can't figure out how to put them into a variable. I know 'char' is for
> one byte, but don't know what type to use for a full string or how to
> concatenate the switches into the string.
>
>   Here's what I've got so far (probably broken from playing with it):
>
> #include <stdio.h>
>
> #define REAL_PATH
> "/home/digimer/projects/mizu-bu/releases/mizu-bu/cgi-bin/exec-priv.pl"
> main(int argc, char *argv[])
> {
>         setuid(geteuid());
>         setgid(getegid());
>        var say;
>        say="Hello";
>
>        int i;
>        for (i=1; i<argc; i++ )
>        {
>                printf("%s%s", argv[i], (i < argc-1) ? " " : "");
>        }
>        printf("\n");
>        printf("%s", say);
> /*        execv(REAL_PATH, av);*/
> }
>
>   Thanks for any help!!
>
> Madison
> --
> The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
> TLUG requests: Linux topics, No HTML, wrap text below 80 columns
> How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
>


-- 
end
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list