我无法冲洗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作为输出?
小唯快跑啊
慕盖茨4494581
阿波罗的战车
噜噜哒
随时随地看视频慕课网APP
相关分类