Need help with c programming. replaceing get with scanf and array arguments

Discussion in 'C Programming' started by nursallt, Jan 13, 2010.

  1. nursallt

    nursallt

    Joined:
    Jan 13, 2010
    Messages:
    1
    Hello there,
    I need help with this program
    its a c program called my shell and it allows custom calls like del instead of rm.

    #include <stdio.h>
    #include <sys/types.h>
    #include <unistd.h>
    #include <stdlib.h>

    main()
    {
    char buffer[1024];
    char *args[256];

    for(; ;)
    {
    printf("Command:");

    if(gets(buffer) == NULL)
    {
    printf("\n");
    exit (0);
    }

    parse(buffer,args);
    printf("%s\n", args[0]);
    /*printf("%s\n", args[1]);
    printf("%s\n", args[2]);*/
    cases(args);
    execute(args);
    }
    }

    parse(buffer,args)
    char *buffer;
    char **args;
    {
    while(*buffer !=NULL)
    {
    while((*buffer == ' ') || (*buffer == '\t'))
    *buffer++ = NULL;


    *args++ = buffer;

    while((*buffer !=NULL) && (*buffer != ' ') && (*buffer != '\t'))
    buffer++;
    }
    *args=NULL;
    }

    execute(args)
    char **args;
    {
    int pid,status;

    if ((pid= fork())<0)
    {
    perror("fork");
    exit(1);
    }

    if (pid==0)
    {
    execvp(*args,args);
    perror(*args);
    exit(1);
    }

    while(wait(&status) !=pid)
    ;
    }


    cases(args)
    char **args;
    {
    char *argu;

    *argu=args[0];


    if (*argu == "help")
    {
    help();
    }

    else if (*argu == "del")
    {
    args[0]="rm";
    execute(args);
    }


    }


    help()
    {
    printf("help")
    }



    i want to replace the get with a scanf but when i do i only seem to beable to get one argument passed. also the whole cases part does not work. What i want to do there is change part of the array before it is passed up so that i could change del to rm ect.

    Any help would be great. Thanks
    nursallt, Jan 13, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jblazi
    Replies:
    18
    Views:
    489
    Anton Vredegoor
    Sep 25, 2003
  2. Edward Diener
    Replies:
    14
    Views:
    4,934
    Josiah Carlson
    Apr 6, 2004
  3. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    scanf (yes/no) - doesn't work + deprecation errors scanf, fopen etc.

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Feb 16, 2006, in forum: C Programming
    Replies:
    185
    Views:
    3,386
    those who know me have no need of my name
    Apr 3, 2006
  4. =?ISO-8859-1?Q?Martin_J=F8rgensen?=

    difference between scanf("%i") and scanf("%d") ??? perhaps bug inVS2005?

    =?ISO-8859-1?Q?Martin_J=F8rgensen?=, Apr 26, 2006, in forum: C Programming
    Replies:
    18
    Views:
    673
    Richard Bos
    May 2, 2006
  5. Søren Schimkat

    Need help with replaceing HTML code i table

    Søren Schimkat, Oct 19, 2003, in forum: Javascript
    Replies:
    1
    Views:
    80
    David Dorward
    Oct 19, 2003
Loading...

Share This Page