雅克18 解剖:请帮我编个程序。

来源:百度文库 编辑:高校问答 时间:2024/03/28 20:22:41
要求实现以下功能:输入文件中有1000行字符串,从文件中读入一行字符串,把这个字符串逆过来,写到输出文件中。比如abc变成cba.
多谢赐教
需要C语言程序

这是delphi的编写方法
使用TStringList对象操作即可

uses StrUtils;

procedure ReverseStringSaveToFile(AInput:AOutput:string);
var
T1,T2:TStringList;
i:Integer;
begin
T1:=TStringList.Create;
T2:=TString.Create;
T1.Items.LoadFromFile(AInputFile);
For i:=0 to T1.Items.Count-1 do
begin
T2.Items.Add(ReverseString(T1.Items.Strings[i]));
end;
T2.Items.SaveToFile(AOutput);
T1.Free;
T2.Free;
end;

用数组

import java.io.*;

public class Untitled1 {
public static void main(String[] args) throws FileNotFoundException,
IOException {
FileReader file = new FileReader("c:/a.txt");
BufferedReader bf = new BufferedReader(file);
StringBuffer s = new StringBuffer(bf.readLine()).reverse();
System.out.println(s);
}
}
这样就没问题了是java的,