一、利用系统调用,从标准输入读取字符串,然后输出,类似c里面的 scanf() printf()
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#define BUFFSISE 4096
int main(void){
int n;
char buf[BUFFSISE];
while((n = read(STDIN_FILENO, buf, BUFFSISE)) > 0)
write(STDOUT_FILENO, buf, n);
exit(0);
}
二、利用c语言函数,当然,c里面有很多字符处理函数了
#include <stdio.h>
int main(void){
char c;
while((c = getc(stdin))!=EOF)
if(putc(c, stdout)==EOF)
puts("put error");
return 0;
}