test3.c
来自「这个是学习嵌入式开发的重要例子」· C语言 代码 · 共 47 行
C
47 行
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#define BUFFER_SIZE 1024int main(int argc, char **argv){ // FILE *popen(const char *command, const char *mode); FILE *fp; //fp = popen("ls -l /tmp", "r"); fp = popen("cat", "w"); if (fp == NULL) { // Upon successful completion, popen() shall return a pointer to an open stream that can be used to read or write to the pipe. Otherwise, it shall return a null pointer and may set errno to indicate the error. fprintf(stderr, "popen() error: %s\n", strerror(errno)); exit(1); } char buf[BUFFER_SIZE]; //memset(buf, 0, BUFFER_SIZE);#if 0 //char *fgets(char *restrict s, int n, FILE *restrict stream); while (fgets(buf, BUFFER_SIZE, fp) != NULL) { fprintf(stdout, "%s", buf); }#endif while (fgets(buf, BUFFER_SIZE, stdin) != NULL) { //fprintf(stdout, "%s", buf); //int fputs(const char *restrict s, FILE *restrict stream); fputs(buf, fp); fflush(fp); } fclose(fp); return 0;}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?