Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Need help with c programming. replaceing get with scanf and array arguments (http://www.velocityreviews.com/forums/t711690-need-help-with-c-programming-replaceing-get-with-scanf-and-array-arguments.html)

nursallt 01-13-2010 07:24 PM

Need help with c programming. replaceing get with scanf and array arguments
 
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


All times are GMT. The time now is 07:23 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.