contributed code goes here
/* nseries
complement the series program,
this program reads a list of strings and adds
an inceremneting postfix each time a string is read
for instance it´ll take an input of foo foO fOO FOO
and output foo1.gif foO2.gif fOO3.gif FOO4.gif
may be used to creat complex download lists
Alaa The Great
3/1/2002
*/
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstdio>
using namespace std;
/* program takes 4 arguments 1-start of series,
2-number of digits (used to pad leading zeros)
and 3-a postfix string value to add after each increment
*/
int main(int argc, char *argv[]) {
int count,pad;
char *postfix; //prefix[256];
char a;
string prefix;
prefix="";
if (argc<4) {
cout<<"need three arguments please"<<endl;
return 1;
}
count=atoi(argv[1]);
pad=atoi(argv[2]);
postfix=argv[3];
do {
a=getchar();
if (a=='\n'||a==EOF&&prefix!="") {
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;
count++;
prefix="";
}
if (a!='\n'&&a!=EOF) prefix=prefix+a;
} while (a!=EOF);
return 0;
}/* 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
3/1/2002
*/
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstdio>
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;
}
start=atoi(argv[1]);
end=atoi(argv[2]);
pad=atoi(argv[3]);
postfix=argv[4];
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++)
generate(start, end, pad, postfix, argv[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;
}
}