I am trying to write a shell program and I have an inputBuffer array that holds the command that was entered. I also have a historyBuffer array that will hold the past 10 commands that were entered. I have the global variable: char historyBuffer[10][MAX_LINE];
(where MAX_LINE == 80) and inside the main I have char inputBuffer[MAX_LINE];
Here is the whole main function:
int main(void){
int flag; //equals 1 if a command is followed by '&'
char *args[MAX_LINE/2+1]; //command line (of 80) must have <40 arguments
int child, //process id of the child process
status; //result from execvp system call
char inputBuffer[MAX_LINE];//buffer to hold the command entered
strcpy(historyBuffer, inputBuffer);
signal(SIGINT, shellHandler); //called when ^C is pressed
while(1){ //program terminates normally inside setup
flag = 0;
printf(" COMMAND->\n");
setup(inputBuffer,args,&flag); //get next comman
child = fork(); //creates a duplicate process
switch(child){
case -1:
perror("Could not fork the process");
break; /* perror is a library routine that displays a system
error message, according to the value of the system
vaiable "errno" which will be set during a function
(like fork) that was unable to successfully
complete its task */
case 0: //here is the child process
status = execvp(args[0], args);
if(status !=0){
perror("Error in execvp");
exit(-2); //terminate this process with error code -2
}
break;
default:
if(flag==0) //handle parent, wait for child
while(child != wait((int *) 0));
}//end switch
}//end while
}//end main
The error is with the line strcpy(historyBuffer, inputBuffer);
I get the error message: expected 'char * __restirct__' but argument is of type 'char(*)[80]'
I'm not sure if it's an issue with the parameters in the strcpy function, if it's an issue with where I'm calling strcpy, or if it's an issue with the way I declared inputBuffer or historyBuffer? Or if it's a completely different issue that I'm oblivious to?