I am getting this compiler error:
gcc -g -Wall -O2 -c -o mybash.o mybash.c
mybash.c: In function ‘main’:
mybash.c:39: warning: implicit declaration of function ‘getline’
mybash.c:41: error: expected expression before ‘)’ token
make: *** [mybash.o] Error 1
It probably has to do with something I don't remember about initializing and using structs in c (its been awhile). Any help would be much appreciated.
Here is my main:
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include "parser.h"
int main(int argc, char *argv[])
{
int bytes_read;
int nbytes = 1000;
char *buf;
char *command = NULL;
char *args[11] = { 0 };
int numargs = 0;
int numcommands = 0;
char *infile = NULL;
char *outfile = NULL;
int background = 0;
struct Command com = {command, {args[11]}, numargs};
struct CommandData data = {{com}, numcommands, infile, outfile, background};
while (1) {
/* Display the current working directory */
printf("\n%s>", getcwd(NULL, 0));
/* Prepare buffer and get the data from the user */
buf = (char *) malloc (nbytes + 1);
bytes_read = getline(&buf, &nbytes, stdin);
int succeed = ParseCommandLine(buf, data*);
if (succeed == 0) {
printf("Bad data, unsuccessful parse\n");
break;
}
printf("%s\n", buf);
break;
}
exit(0);
}
And the is the Header Info:
struct Command {
char *command;
char *args[11];
int numargs;
};
struct CommandData {
struct Command TheCommands[20]; /* the commands to be
executed. TheCommands[0] is the first command
to be executed. Its output is piped to
TheCommands[1], etc. */
int numcommands; /* the number of commands in the above array */
char *infile; /* the file for input redirection, NULL if none */
char *outfile; /* the file for output redirection, NULL if none */
int background; /* 0 if process is to run in foreground, 1 if in background */
};
extern int ParseCommandLine(char *, struct CommandData *);