ucfile.c
来自「c语言开发方面的经典问题,包括源代码.c语言开发所要注意的问题,以及在嵌入式等各」· C语言 代码 · 共 60 行
C
60 行
/* * File: ucfile.c * -------------- * This program updates the contents of a file by converting all * letters to upper case. */#include <stdio.h>#include <ctype.h>#include "genlib.h"#include "simpio.h"/* Private function prototypes */static void UpperCaseCopy(FILE *infile, FILE *outfile);/* Main program */main(){ string filename, temp; FILE *infile, *outfile; printf("This program converts a file to upper case.\n"); while (TRUE) { printf("File name: "); filename = GetLine(); infile = fopen(filename, "r"); if (infile != NULL) break; printf("File %s not found -- try again.\n", filename); } temp = tmpnam(NULL); outfile = fopen(temp, "w"); if (outfile == NULL) Error("Can't open temporary file"); UpperCaseCopy(infile, outfile); fclose(infile); fclose(outfile); if (remove(filename) != 0 || rename(temp, filename) != 0) { Error("Unable to rename temporary file"); }}/* * Function: UpperCaseCopy * Usage: UpperCaseCopy(infile, outfile); * -------------------------------------- * This function copies the contents of infile to outfile, * converting alphabetic characters to upper case as it does so. * The client is responsible for opening and closing the files. */static void UpperCaseCopy(FILE *infile, FILE *outfile){ int ch; while ((ch = getc(infile)) != EOF) { putc(toupper(ch), outfile); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?