What I'm supposed to do is to write a "photo album" program which will take a list of pictures and generate HTML files to display them.
I can display an image in html with the img src tag.
I can make a link to a different page by using the a href tag. For example, to link to the
page "page2.html" with the link text reading "Next Page"
But what I
must do is write a program that:
• Inputs a list of picture files from a file
• Puts the pictures in order based on their name
• Generates a web page (output file) for each picture, which includes:
• The picture
• A link to the next page in the list
• A link to the previous page in the link
I'm inputing the pics from a txt file that I've already created.
This is what I have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
|
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
using namespace std;
const int ARRAY_SIZE = 10;
void writeHtml (string lines[ARRAY_SIZE], int nLines)
{
string html = ".html";
for (int i = 0; i < nLines; i++)
{
string line = lines[i];
string fileName = line + html;
ofstream htmlFile (fileName.c_str());
htmlFile << "" << line << "" << endl;
htmlFile << "" << endl;
htmlFile << "" << endl;
htmlFile << "" << endl;
if (i != 0)
{
string previousLine = lines[i - 1];
string previousFileName = previousLine + html; htmlFile << "Previous: " << previousLine << "" << endl; htmlFile << "" << endl;
}
if (i + 1 < nLines)
{
string nextLine = lines[i + 1];
string nextFileName = nextLine + html; htmlFile << "Next: " << nextLine << "" << endl; htmlFile << "" << endl;
}
htmlFile.close();
}
}
void sortLines(string lines[ARRAY_SIZE], int nLines)
{
bool stillSorting = true;
while (stillSorting)
{
stillSorting = false;
for (int i = 0; i < nLines - 1; i++)
{
string s1 = lines[i];
string s2 = lines[i + 1];
if (s1 > s2)
{
lines[i] = s2;
lines[i + 1] = s1;
stillSorting = true;
}
}
}
}
void run()
{
string line;
string lines[ARRAY_SIZE];
ifstream inputFile ("list.txt");
int i = 0;
while (! inputFile.eof() )
{
getline (inputFile,line);
lines[i] = line; i++;
}
int nLines = i;
inputFile.close();
sortLines(lines, nLines);
for (int j = 0;
j < nLines; j++)
{ cout << lines[j] << endl;
}
writeHtml(lines, nLines);
}
int main()
{
run();
return (0);
}
|
But I don't think it does what I want it to. I'm not sure how it's supposed to appear when I run it though.
Any suggestions?