c - Why does read not work yet fgets work fine in my program? -


so specific part of program looks this:

printf("please input command:\n>"); while 1 {     if ((int c = read(stdin_fileno, input, buffer_size) == 0) {         break;     }     rest of program uses strtok break input      down , store in array. pass function checks      various commands , prints whatever command      suppose or gives syntax error incorrect commands      printf(">"); //last line  } 

so here's happens:

please input command: addperson batman >person added blahblah error: incorrect syntax 

for reason doesn't print: ">". everytime enter after says same thing right commands.

but if use this:

printf("please input command:\n>"); while 1 {     if (fgets(input, buffer_size, stdin) == null) {         break;     }     ...     printf(">");  } 

i get:

please input command: > add_person batman person added > blahbagwa incorrect syntax > add_person superman person added 

notice how ">" appears in each output? don't know why read isn't working properly; perhaps understand of read isn't good. have idea?

read() block until has received enough input fill entire buffer fgets() return buffer each entered line.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -