⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 test3.c

📁 这个是学习嵌入式开发的重要例子
💻 C
字号:
#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -