I am always returning junk values to cmdLine in main.
I have tried declaring cmdLine as: char * cmdLine
I also tried with the current code sending *cmdLine but then i get a pointer from int without cast error.
I want to send the char pointer to the sub-routine, have the sub routine put the string at that address and exit leaving me with a variable with a string in it in main. This is a re-occurring issue in code that I write.
Thanks!
Code:
const char *builtInCmd[3] = {
"cd",
"exit",
"help"};
int main (int argc, char **argv)
{
// Local Variables
int childPid, isBuiltIn;
char cmdLine[50];
if(readCommandLine(cmdLine) == 1) {
printf("The command is %s\n", cmdLine);
isBuiltIn = isBuiltInCommand(cmdLine);
printf("The builtin Numb is:%i", isBuiltIn);
}
}
//Read user input and tare it down
int readCommandLine(char *cmd_p){
char buf[80], *p;
fflush (stdout);
cmd_p = fgets (buf, 80, stdin);
if(strlen(cmd_p) > 0)
return 1;
return -1;
}