我無法沖洗stdin如何刷新stdin?為什么它不能在以下代碼片段中工作?#include <string.h>#include <stdio.h>#include <malloc.h>#include <fcntl.h>int main(){
int i=0,j=0, sat;
char arg[256];
char * argq;
argq = malloc(sizeof(char)*10);
printf("Input the line\n");
i=read(0, arg, sizeof(char)*9);
arg[i-1]='\0';
fflush(stdin);
i=read(0, argq, sizeof(char)*5);
argq[i-1]='\0';
puts(arg);
puts(argq);
return 0;}現在,如果我將輸入作為11個字符,則只應讀取9個,但是stdin中剩余的兩個字符不會被刷新并在argq中再次讀取。為什么?輸入:123 456 789產出:123 456 89為什么我將這89作為輸出?
我無法沖洗stdin
慕碼人8056858
2019-09-12 14:10:18