Created
April 8, 2017 02:48
-
-
Save MggMuggins/2e7a745e0808ef5fe9c1da56b4b4cc29 to your computer and use it in GitHub Desktop.
Small D program to do some stuff with a file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Pseudocode | |
* Read Infomation on what needs to happen from the user | |
* Open file | |
* Read each line of the file to an array of strings | |
* Apply operations to array of strings | |
* Write each element of the array to the file | |
* | |
* Syntax: | |
* Arguments go in this order: Input File, Output file, Prefix, Suffix | |
* | |
*/ | |
import std.stdio, std.file, std.string; | |
/* | |
string readString (string text) { | |
string stringOut; | |
writeln(text); | |
string output = strip(readln()); | |
return stringOut; | |
}*/ | |
int main(string[] args) { | |
File inFile, outFile; | |
string inLine; | |
/* | |
string prefix = readString("What do you want before each line of the file? "); | |
string suffix = readString("What goes at the end of each line?"); | |
string input = readString("What file do we apply this operation to?"); | |
string output = readString("What file do we dump this operation to?");*/ | |
string input = args[1]; | |
string output = args[2]; | |
string prefix = args[3]; | |
string suffix = args[4]; | |
try { | |
inFile = File(input, "r"); | |
} catch (std.exception.ErrnoException) { | |
writeln("We can't read that file!"); | |
return 1; | |
} | |
outFile = File(output, "w"); | |
while (!inFile.eof()) { | |
inLine = strip(inFile.readln()); | |
outFile.writeln(prefix, inLine, suffix); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You missed a change to name it Appen.d....