ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Ubuntu 8.04 - Fedora 9 on an AMD 64bit Machine
Posts: 101
Rep:
a small program
Hi, I am trying to do a code which will help me write the names of some files on a web page, here is what I have tried:
Code:
#include <iostream>
using namespace std;
int main()
{
for (int i = 1; i<10; i++);
cout << "http://download.quran.islamway.com/quran3/236/00" << i;
cout << ".rm\n";
return 0;
}
I want to make it print the files on a web page, the files are 114 files in total. The first is 001.rm and the last is 114, how can this be done? I am here trying to get the first 9 files, it is because of those 00 before the first 9 files! I was then to get others starting from 10.rm to 99.rm with a 0 in front of them, then 100.rm to 114.rm
Also, can I direct the outputs to be downloaded with wget? I mean all these files one after another?
I'll just comment on the code and not if this is the best method of completing your task.
Your for loop has a semi colon after it and therefore this is the end of the control structure for the loop, I think what you meant to do is:
Code:
...
for (int i = 1; i<10; i++)
cout << "http://download.quran.islamway.com/quran3/236/00" << i << ".rm\n";
...
Distribution: Ubuntu 8.04 - Fedora 9 on an AMD 64bit Machine
Posts: 101
Original Poster
Rep:
But how may I write the code to give me the file names as I want.
As I said, files with a name less than 10 have 00irm form, while files of a name greater than 9 and smaller than 100 have a 0iirm form and files of a name greater than 99 has an iiirm form?
I did this:
Code:
#include <iostream>
using namespace std;
int main()
{
for (int i=1; i<10; i++)
cout << "http://download.quran.islamway.com/quran3/236/00" << i << ".rm\n";
for (int i=10; i<100; i++)
cout << "http://download.quran.islamway.com/quran3/236/0" << i << ".rm\n";
for (int i=100; i<115; i++)
cout << "http://download.quran.islamway.com/quran3/236/" << i << ".rm\n";
return 0;
}
I just compiled and ran it and got the results you wanted.
Code:
avinash@haydn ~ $ ./main.bin | wget -i -
--14:32:19-- http://download.quran.islamway.com/quran3/236/001.rm
=> `001.rm'
Resolving download.quran.islamway.com... 64.62.191.252
Connecting to download.quran.islamway.com|64.62.191.252|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 97,304 (95K) [application/octet-stream]
100%[====================================>] 97,304 92.76K/s
That will essentially take the output of your program and pipe it into wget for downloading.
Edit: you can split that condition into two and just and (i.e. use "&&") the two together so the whole expression is true only when both parts are true.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.