c - Why is this Annoying Line interfering with my output? -
i have piece of code developed address problem have in large program developing.
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <cstring> #include <cstdlib> #include <sys/types.h> #include <sys/wait.h> #include <errno.h> #include <limits.h> #include <string> #include <iostream> using namespace std; void processline (char []); void readline(char []); const int limit = 512; int main(int argc, char *argv[]) { char oneline[line_max]; readline(oneline); return 0; } void readline(char line[]) { processline(line); printf("annoying line\n"); } void processline(char line[]) { pid_t process; int child_status; string input; cout << "input: "; cin >> input; process = fork(); if(process == 0) { // nothing } else { //parent if(input == "quit") { printf("quit command found ! \nexiting "); for(int = 0;i < 3;i++) { printf("."); fflush(stdout); sleep(1); } printf("\n"); exit(0); } else { wait(&child_status); } } } my goal simple, when user enter quit.
i display
quit command found
exiting ...
and there delay of 1 second between each of these 3 dots.
however output
quit command found
exiting . annoying line..
i wonder how come annoying line prints after first dot, though it's calling function , not it's turn printed terminal ????
any ideas. spent 10 hours trying fix
in child process // nothing falls through , returns main() , prints line. fork() makes 2 copies both continue executing. child calls exec() run else (never returning), aren't doing that.
Comments
Post a Comment