㈠ c语言编程,从键盘输入一字符串,将其中的小写字母全部转换成大写字母
代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main() {
FILE *fp;
if((fp=fopen("123.txt","a"))==NULL)
printf("file cannot open ");
else
printf("file opened for writing ");
char ch;
while((ch = getchar()) != ' '){
fputc(toupper(ch),fp);
}
fputc('#',fp);
if(fclose(fp)!=0)
printf("file cannot be closed ");
else
printf("file is now closed ");
return 0;
}
程序运行如下:
(1)c语言大小写转换程序代码扩展阅读
C语言对文件输入可以用fputc函数,只需要循环遍历输入,把输入的每个字符串进行大写的转换,大小写转换可以通过C语言内置于ctype.h的toupper函数来转换,没转换一个字符串可以直接写入到文件中,最后在追加一个#好字符,就完成功能了。
㈡ c语言编程:字符串中大小写字母转换
思路:利用对应大小写字符的ASCII码相差32,则遍历输入的字符串,判断每个字符是大写字母还是小写字母,如果是大写字母则自加32就是对应的小写字母,如果是小写字母则自减32就是其对应的大写字母。
参考代码:
#include<stdio.h>
intmain()
{
chara[100];
inti;
gets(a);
for(i=0;a[i]!='