Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C Programming: I can't get my user input function to work in my main. Please help :) #include #define MAXINPUT 2048 #define MAXARGS 512

In C Programming:

I can't get my user input function to work in my main. Please help :)

#include

#define MAXINPUT 2048

#define MAXARGS 512

static bool reading_input = false;

void userInput(char *user_input[], int *bgStatus, char inputFile[], char outputFile[], int pid);

// main-------------------------

int main(){

int pid = getpid();

int cont = 1;

int exitStatus = 0;

int bgStatus = 0;

char *prompt = (getenv("PS1") != NULL) ? getenv("PS1") : "";

char *input = NULL;

size_t input_size = 0;

char *args[MAXARGS];

char input_copy[MAXINPUT];

int num_args = 0;

pid_t child_pid;

int child_status;

while(1) {

while ((child_pid = waitpid(-1, &child_status, WNOHANG)) > 0) {

if (WIFEXITED(child_status)) {

fprintf(stderr, "Child process %jd done. Exit status %d. ", (intmax_t) child_pid, WEXITSTATUS(child_status));

} else if (WIFSIGNALED(child_status)) {

fprintf(stderr, "Child process %jd done. Signaled %d. ", (intmax_t) child_pid, WTERMSIG(child_status));

} else if (WIFSTOPPED(child_status)) {

kill(child_pid, SIGCONT);

fprintf(stderr, "Child process %jd stopped. Continuing. ", (intmax_t) child_pid);

}

}

userInput(user_input, &bgStatus, inputFile, outputFile, pid);

if(strcmp(user_input[0], "exit") == 0) {

//exit;

}

return 0;

}

// userInput---------------------------------------------------------

void userInput(char *user_input[], int *bgStatus, char inputFile[], char outputFile[], int pid){

size_t input_size = 0;

char *prompt = (getenv("PS1") != NULL) ? getenv("PS1") : "";

char input[MAXINPUT];

printf("%s", prompt);

fflush(stdout);

ssize_t num_chars = getline(&input, &input_size, stdin);

reading_input = true;

if (num_chars == -1 && errno == EINTR) {

clearerr(stdin);

fprintf(stderr, " ");

}

// Check if input is blank and do nothing but return

if(!strcmp(input, "")){

//

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions

Question

Define offboarding. Why is it important?

Answered: 1 week ago