useupper.c
来自「《Beginning Linux Programming》书的配置实例源代码。」· C语言 代码 · 共 34 行
C
34 行
/* This code, useupper.c, accepts a file name as an argument and will respond with an error if called incorrectly. */#include <unistd.h>#include <stdio.h>int main(int argc, char *argv[]){ char *filename; if(argc != 2) { fprintf(stderr, "usage: useupper file\n"); exit(1); } filename = argv[1];/* That done, we reopen the standard input, again checking for any errors as we do so, and then use execl to call upper. */ if(!freopen(filename, "r", stdin)) { fprintf(stderr, "could not redirect stdin to file %s\n", filename); exit(2); } execl("./upper", "upper", 0);/* Don't forget that execl replaces the current process; provided there is no error, the remaining lines are not executed. */ fprintf(stderr, "could not exec upper!\n"); exit(3);}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?