Skip to Content

Revision of series from Fri, 30/12/2005 - 1:00pm

The revisions let you track differences between multiple versions of a post.

/* Series Generator generates a string with a numeric series in the middle, like foo01.gif foo02.gif .... foo99.gif programs output may be redirected as its input allowing the creation of very complex series like /year1981/foo01.gif .... /year2002/foo90.gif useful in creating download lists Alaa The Great
  1. /1/2002
  • /
using namespace std; void generate(int start, int end, int pad, char *postfix, string prefix ) ; /* program should have at least 4 arguments 1-first and 2-last values of the series 3-number of digits (needed to pad leading zeros) 4-string after the series any arguments that follows will be assumed to be a string to generate a series for (string at the begining of the series) if only 4 arguments are given the program asks for input of string to put in the begining of the series (terminates when EOF is enetered) */ int main( int argc, char *argv[]) { int start, end, pad; char *postfix; char a; string prefix; prefix=""; if (argc<5) { cout<<endl<<"need more arguments"<<endl; return 1; } if (argc==5) { do { a=cin.get(); if (a=='\n'||a==EOF&&prefix!="") { generate(start,end,pad,postfix,prefix); prefix=""; } if (a!='\n'&&a!=EOF) prefix=prefix+a; } while (a!=EOF); } else { for (int i=5; i<argc; i++) } return 0; } void generate(int start, int end, int pad, char *postfix, string prefix) { for (int count=start; count<=end; count++) { cout<<prefix; if (count!=0) for(int k=pad; pow(10.0,(k-1))>count; k--) cout<<0; else for (int k=pad; k>1; k--) cout<<0; cout<<count<<postfix<<endl; } }


Dr. Radut | book