C Exercise Example 98
100 cases of classic C language
Title: keyboard input from a string, all lowercase letters to uppercase letters, and then output to a disk file "test" to save. Enter the string! End.
Program Analysis: None.
Source Code:
// Created by www.w3big.com on 15/11/9. // Copyright © 2015年 本教程. All rights reserved. // #include<stdio.h> #include<stdlib.h> int main() { FILE*fp=NULL; char str[50]; int i,len; printf("输入一个字符串:\n"); gets(str); len=strlen(str); for(i=0;i<len;i++) { if(str[i]<='z'&&str[i]>='a') str[i]-=32; } if((fp=fopen("test","w"))==NULL) { printf("error: cannot open file!\n"); exit(0); } fprintf(fp,"%s",str); fclose(fp); system("pause"); return 0; }
Run the above example output is:
输入一个字符串: www.w3big.com