编一个程序,从文件“d:\test1.txt”上读入一行字符串
然后把其中的大写字母全部转换成小写字母,最后把转换后的字符串输出到一个磁盘文件“d:\test2.txt”中用C语言,谢谢!...
然后把其中的大写字母全部转换成小写字母,最后把转换后的字符串输出到一个磁盘文件“d:\test2.txt”中
用C语言,谢谢! 展开
用C语言,谢谢! 展开
4个回答
展开全部
import java.io.*;
public class Main{
//把字符串中的大写字母转化成小写字母
static String fun(String str){
char[] ch = str.toCharArray();
StringBuffer strb = new StringBuffer();
for(int i=0;i<ch.length;i++){
if(ch[i]>='A'&&ch[i]<='Z')
strb.append((char)(ch[i]+32));
else
strb.append(ch[i]);
}
return strb.toString();
}
public static void main(String args[]) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\test.txt")));//读文件
String str = null;
try {
while((str = br.readLine())!=null){
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("d:\\test2.txt")));//转化大写字母后写文件
pw.println(fun(str));
pw.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
public class Main{
//把字符串中的大写字母转化成小写字母
static String fun(String str){
char[] ch = str.toCharArray();
StringBuffer strb = new StringBuffer();
for(int i=0;i<ch.length;i++){
if(ch[i]>='A'&&ch[i]<='Z')
strb.append((char)(ch[i]+32));
else
strb.append(ch[i]);
}
return strb.toString();
}
public static void main(String args[]) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream("d:\\test.txt")));//读文件
String str = null;
try {
while((str = br.readLine())!=null){
PrintWriter pw = new PrintWriter(new OutputStreamWriter(new FileOutputStream("d:\\test2.txt")));//转化大写字母后写文件
pw.println(fun(str));
pw.flush();
}
} catch (IOException e) {
e.printStackTrace();
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
c语言代码如下:
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
void main()
{
char *inpath = "C:\\test1.txt";
char *outpath = "C:\\test2.txt";
FILE* fin = NULL;
FILE* fout = NULL;
fin = fopen(inpath,"r");
fout = fopen(outpath,"w+");
if (!fin)
{
printf("open file : %s failed!\n",inpath);
return;
}
char ch;
while(fread(&ch,sizeof(char),1,fin))
{
if(ch>='A' && ch<='Z')
ch += 32;
printf("%c\n",ch);
fwrite(&ch,sizeof(char),1,fout);
}
fclose(fin);
fclose(fout);
printf("done !\n");
system("pause");
}
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
void main()
{
char *inpath = "C:\\test1.txt";
char *outpath = "C:\\test2.txt";
FILE* fin = NULL;
FILE* fout = NULL;
fin = fopen(inpath,"r");
fout = fopen(outpath,"w+");
if (!fin)
{
printf("open file : %s failed!\n",inpath);
return;
}
char ch;
while(fread(&ch,sizeof(char),1,fin))
{
if(ch>='A' && ch<='Z')
ch += 32;
printf("%c\n",ch);
fwrite(&ch,sizeof(char),1,fout);
}
fclose(fin);
fclose(fout);
printf("done !\n");
system("pause");
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<stdio.h>
int main(){
FILE *fin=fopen("D:\\test1.txt","r");
FILE *fout=fopen("D:\\test2.txt","w");
char s[1024],ch;
int i;
fgets(s, 1023, fin);
for(i=0; ch=s[i]; i++)
if(ch>='A' && ch<='Z')
s[i]+=32;
fputs(s,fout);
fclose(fin);
fclose(fout);
return 0;
}
int main(){
FILE *fin=fopen("D:\\test1.txt","r");
FILE *fout=fopen("D:\\test2.txt","w");
char s[1024],ch;
int i;
fgets(s, 1023, fin);
for(i=0; ch=s[i]; i++)
if(ch>='A' && ch<='Z')
s[i]+=32;
fputs(s,fout);
fclose(fin);
fclose(fout);
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询