|
Revision 6, 0.8 kB
(checked in by jcc7, 3 years ago)
|
Made more progress in developing convertToWiki and added some files.
|
| Line | |
|---|
| 1 |
import std.stream; |
|---|
| 2 |
import std.stdio; |
|---|
| 3 |
|
|---|
| 4 |
void main(char[][] args) |
|---|
| 5 |
{ |
|---|
| 6 |
int i; |
|---|
| 7 |
char[][] arr; |
|---|
| 8 |
char[][] sortedArr; |
|---|
| 9 |
char[] ln; |
|---|
| 10 |
|
|---|
| 11 |
if(args.length < 2) |
|---|
| 12 |
{ |
|---|
| 13 |
writefln("sort_file: Provide a file as an argument to sort it."); |
|---|
| 14 |
return; |
|---|
| 15 |
} |
|---|
| 16 |
|
|---|
| 17 |
char[] inFileName = args[1]; |
|---|
| 18 |
File inFile = new File(inFileName); |
|---|
| 19 |
File outFile = new File(args[1] ~ ".sorted.txt", FileMode.OutNew); |
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
writefln("Sorting: %s", inFileName); |
|---|
| 23 |
|
|---|
| 24 |
while (!inFile.eof()) |
|---|
| 25 |
{ |
|---|
| 26 |
ln = inFile.readLine(); |
|---|
| 27 |
arr.length = arr.length + 1; |
|---|
| 28 |
arr[arr.length - 1] = ln; |
|---|
| 29 |
} |
|---|
| 30 |
inFile.close(); |
|---|
| 31 |
|
|---|
| 32 |
sortedArr = arr.sort; |
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 |
for(i = 0; i < sortedArr.length; i++) |
|---|
| 36 |
{ |
|---|
| 37 |
outFile.writeLine(sortedArr[i]); |
|---|
| 38 |
debug writefln("%s", sortedArr[i]); |
|---|
| 39 |
} |
|---|
| 40 |
} |
|---|