Skip to Content

nseries

/* 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;
}


Dr. Radut | book