Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <cstring>
- #include <cstdlib>
- int number_of_chars;
- char chars_to_use[200];
- using namespace std;
- ofstream out;
- void outputcout(string x, int number_of_chars_left, string separator) {
- char c;
- if(number_of_chars_left==0) {
- cout << x << separator;
- return;
- }
- else {
- for(c=0; c<number_of_chars; c++) {
- outputcout(x+chars_to_use[c], number_of_chars_left-1, separator);
- }
- }
- }
- void output(string x, int number_of_chars_left, string separator) {
- char c;
- if(number_of_chars_left==0) {
- out << x << separator;
- return;
- }
- else {
- for(c=0; c<number_of_chars; c++) {
- output(x+chars_to_use[c], number_of_chars_left-1, separator);
- }
- }
- }
- void usage() {
- cerr << "usage: wlg (-l|-w) (no_chars) (chars) [output file]" << endl;
- exit(1);
- }
- int main(int argc, char *argv[]) {
- int how_many;
- string separator;
- if(argc<4)
- usage();
- if(!strcmp(argv[1], "-l"))
- separator="\n";
- else if(!strcmp(argv[1], "-w"))
- separator="\r\n";
- how_many=atoi(argv[2]);
- strcpy(chars_to_use, argv[3]);
- number_of_chars=strlen(chars_to_use);
- if(argc==4)
- outputcout("", how_many, separator);
- if(argc==5) {
- out.open(argv[4]);
- output("", how_many, separator);
- out.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment