Despairy 0 Light Poster

i wrote a program that needs to act like the SHELL in linux
everytime the user enters a command the shell needs to get it
and do the action by sending a fork child to do so
now i read using FGETS and get a char array containing the command entered
by the user
and than i seperate the words like this :

char **getArgs(const char* str,int *numOfStrings)
{
	int i=0;
	char **argv2;
	
	int newCell=0;
	
	argv2=malloc((*numOfStrings)*sizeof(char**));
	argv2[(*numOfStrings)-1]=realloc
			(argv2[(*numOfStrings)-1],sizeof(char*)*MAX_STR_LEN);
	
	for (;i<strlen(str);i++)
	{
		if (isspace(str[i]))
		{
			i++;
			argv2[(*numOfStrings)-1][newCell]='\0';
			(*numOfStrings)++;	
			argv2=realloc(argv2,((*numOfStrings)-1)*sizeof(char**));
			newCell=0;
			argv2[(*numOfStrings)-1]=realloc
				(argv2[(*numOfStrings)-1],sizeof(char*)*MAX_STR_LEN);
		}
		argv2[(*numOfStrings)-1][newCell]=str[i];
		newCell++;
	}
	return(argv2);
}

and the child calling execlp is the following

void doSon(const char* str)
{
	int numOfStrings=1;
	char **newStr=getArgs(str,&numOfStrings);
	if((execlp(str,str,newStr[1])!=0))
		perror("execlp error");
}

{same with execvp}

the problem is when the user entered "ls -l"
or anything with 2 words. it wont work.
and say

execlp error: No such file or directory

thanks for helping !

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.