I'm trying to send an array of a predefined size of user input to the execvp function, however I receive a warning from the compiler. There is ratio of text-code that stackoverflow requires so I'm just trying to fill it up so that I can submit my post. Don't bother reading this, just head down to the code below. Thank you in advance!!!
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#define INPUTSIZE 50
#define INPUTCOUNT 10
int parseInput(char string[*][INPUTSIZE]);
void main(int argc, char **argv){
char prompt = '#', shellInput[INPUTCOUNT][INPUTSIZE];
pthread_t thread;
pid_t processID;
int rc;
while(1){
printf("%c", prompt);
if(parseInput(shellInput)==EOF){
exit(EXIT_SUCCESS);
}
processID = fork();
if(processID == 0){
execvp(shellInput[0], shellInput);
printf("Uknown command\n");
}
printf("Nope.gif!\n");
fflush(stdout);
}
}
int parseInput(char string[INPUTCOUNT][INPUTSIZE]){
char *inputString, *tempString;
int i, status;
size_t bytecount = INPUTSIZE+1;
inputString = (char *)malloc(INPUTCOUNT*INPUTSIZE);
tempString = (char *)malloc(INPUTSIZE);
status = getline(&inputString, &bytecount, stdin);
tempString = strtok(inputString, " ");
for(i = 0; i < INPUTCOUNT && tempString != NULL; i++){
strncpy(string[i], tempString, INPUTSIZE);
tempString = strtok(NULL, " \n\r");
}
strncpy(string[i], "NULL", sizeof(NULL));
return status;
}
strncpy(string[i], "NULL", sizeof(NULL));"NULL" != NULL