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

Joined
Jan 13, 2010
Messages
1
Reaction score
0
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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top