LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 06-13-2007, 01:07 PM   #1
nmansour
Member
 
Registered: Sep 2006
Location: Chicago
Distribution: Ubuntu 8.04 - Fedora 9 on an AMD 64bit Machine
Posts: 101

Rep: Reputation: 15
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?

Noha Mansour
 
Old 06-13-2007, 01:21 PM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
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";
...
 
Old 06-13-2007, 01:46 PM   #3
Avinash
LQ Newbie
 
Registered: Dec 2006
Posts: 11

Rep: Reputation: 0
If you want to direct the output into wget, output each URL on a newline (\n).

Pipe this into a file , then wget -i $output file.

Understand?

./yourprogram > output.txt
wget -i output.txt

You can pipe it straight into wget if you want.

-Avinash
 
Old 06-13-2007, 01:46 PM   #4
nmansour
Member
 
Registered: Sep 2006
Location: Chicago
Distribution: Ubuntu 8.04 - Fedora 9 on an AMD 64bit Machine
Posts: 101

Original Poster
Rep: Reputation: 15
Yes, it solved my compilation problem. I hope to get a complete solution.

Noha
 
Old 06-13-2007, 02:11 PM   #5
nmansour
Member
 
Registered: Sep 2006
Location: Chicago
Distribution: Ubuntu 8.04 - Fedora 9 on an AMD 64bit Machine
Posts: 101

Original Poster
Rep: Reputation: 15
Avinash,

How to pipe it staight? Excuse my ignorance in C++, I am a newbie doing a self-study.

Noha
 
Old 06-13-2007, 02:13 PM   #6
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Use some if statements in your for loop?
 
Old 06-13-2007, 02:17 PM   #7
nmansour
Member
 
Registered: Sep 2006
Location: Chicago
Distribution: Ubuntu 8.04 - Fedora 9 on an AMD 64bit Machine
Posts: 101

Original Poster
Rep: Reputation: 15
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;
}
Noha
 
Old 06-13-2007, 02:32 PM   #8
Avinash
LQ Newbie
 
Registered: Dec 2006
Posts: 11

Rep: Reputation: 0
This should work!

Code:
./main.bin | wget -i -

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.
 
Old 06-13-2007, 02:36 PM   #9
nmansour
Member
 
Registered: Sep 2006
Location: Chicago
Distribution: Ubuntu 8.04 - Fedora 9 on an AMD 64bit Machine
Posts: 101

Original Poster
Rep: Reputation: 15
but how to use the if statement.
I could not find how to have a condition such as 9 < i < 100, say.

Noha
 
Old 06-13-2007, 02:38 PM   #10
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
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.

Last edited by Nylex; 06-13-2007 at 02:40 PM.
 
Old 06-13-2007, 02:41 PM   #11
nmansour
Member
 
Registered: Sep 2006
Location: Chicago
Distribution: Ubuntu 8.04 - Fedora 9 on an AMD 64bit Machine
Posts: 101

Original Poster
Rep: Reputation: 15
Nylex,
Please be more detailed,

Appreciate it,

Noha
 
Old 06-13-2007, 02:42 PM   #12
Avinash
LQ Newbie
 
Registered: Dec 2006
Posts: 11

Rep: Reputation: 0
Why not do this?

It's shorter
Code:
#include <iostream>
using namespace std;

int main()
{
  for (int i=1; i<100; i++)
    printf("http://download.quran.islamway.com/quran3/236/%.3d.rm\n",i);
  return 0;
}
 
Old 06-13-2007, 02:45 PM   #13
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by nmansour
Nylex,
Please be more detailed,

Appreciate it,

Noha
9 < i < 100 is the same as i > 9 and i < 100, right?

Code:
if(i > 9 && i < 100)
{
  ...
}
 
Old 06-13-2007, 02:48 PM   #14
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
Quote:
Originally Posted by Avinash
Code:
#include <iostream>
using namespace std;

int main()
{
  for (int i=1; i<100; i++)
    printf("http://download.quran.islamway.com/quran3/236/%.3d.rm\n",i);
  return 0;
}
You need to include <cstdio> to use printf().
 
Old 06-13-2007, 02:49 PM   #15
Avinash
LQ Newbie
 
Registered: Dec 2006
Posts: 11

Rep: Reputation: 0
I just ran it through g++
 
  


Reply

Tags
automated, downloading, wget


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Small database program? PatrickMay16 General 1 06-15-2006 12:32 AM
Please help me with small college program stuckatc Linux - Software 4 06-02-2006 08:13 AM
please help with small sort program stuckatc Linux - Newbie 1 06-01-2006 02:17 PM
Need help with small program batalia Linux - Newbie 8 11-07-2005 03:41 PM
Compile a small program Dauer Ubuntu 2 11-05-2005 05:17 AM


All times are GMT -5. The time now is 09:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration