Here is the code .. By the way am using Minix cc compiler. Every thing was working just fine untill i added the function
Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <errno.h>
#include <string.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/stat.h>
extern char **getline();
char **getNextCommand(Char **args,int order,int npipes);/* error at this line */
int main() {
int i,j, npipes,status;
pid_t pid , npid;
char **args, **new_args, **args_temp;
int * pipe_fd;
while(1) {
/* Some code here ... */
if( (args = getNextCommand(args,j,npipes)) == NULL){
fprintf(stderr, "Un expected error\n");
exit(2);
}
/* Some code here ... */
}
char ** getNextCommand(Char **args,int order,int npipes)
{
int j,i,count;
char ** new_args;
if(order == 0){
j =0;
for( i=0;args[i] != NULL && strcmp(args[i],"|") != 0 ; i++)
new_args[j++] = args[i];
new_args[i] = NULL;
}
else{
count = 0; i =0; j =0;
while(args[i] != NULL && strcmp(args[i] , "|") == 0){
count ++; i++;
}/* end: while*/
if(args[i] == NULL){
fprintf(stderr, "command not properly formatted");
return NULL;}
while(strcmp(args[i], "|") != 0 && args[i] != NULL){
new_args[j++] = args[i++];
}/* end: while */
new_args[j] =NULL;
}/* end else */
return new_args;
}/* end getNextCommand */