Skip to content

Instantly share code, notes, and snippets.

@MggMuggins
Created April 8, 2017 02:48
Show Gist options
  • Save MggMuggins/2e7a745e0808ef5fe9c1da56b4b4cc29 to your computer and use it in GitHub Desktop.
Save MggMuggins/2e7a745e0808ef5fe9c1da56b4b4cc29 to your computer and use it in GitHub Desktop.
Small D program to do some stuff with a file.
/*
* 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;
}
@Campinator
Copy link

You missed a change to name it Appen.d....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment