|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
| Sponsored Links |
|
|
|
|||||
|
It does give that I think but only for a split second as it exits the program at that exact moment.
Edit: Oh yeah, when I hit "y" or "Y" it does go so far as to create the file before exiting. The file's source code is blank, however.
__________________
Last edited by shibbythestoner; 09-13-2007 at 06:39 PM. |
|
|||||
|
Quote:
Code:
system("title <HTML> Writer");
I need to go now, but I'll look at the rest of the code later. |
| Sponsored Links |
|
|
|
|||||
|
Quote:
Quote:
I've tried taking it out of the loop and got rid of the option whether or not to write but it gets as far as the first occurence of cin.get(); and quits on me again.
__________________
|
|
|||||
|
I'm sorry I haven't answered you yet, but I'm on holidays, so I don't have much time to sit on the computer. It means I don't have the time to look your code through right now, but I've some suggestions.
When you're getting input, which you want to compare, let's say single characters, then don't use strings! It's unnecessary, and sometimes it can be hard to compare with them. Like in your code, you want to let the user input 'y'/'Y' or something else. Instead of getting it into a string, use a char or an int. std::cin and char or int for numbers/single characters, and std::getline for strings. Also, to get a better overview of your code, replace many of your if-statements with switch-statements. It will be easier to read then. Try following my guidelines, if you want to, and then post the new code. |
|
|||||
|
Quote:
So for small things with no spaces I will use char instead of string, sure. I'd say that's a good plan. I'll use getline for strings; I know how to do that and I have the basics of switch statements down (though I am not oft to use them, so it'll be good practice for me anyway). Thanks for your advice, I'll re-write my code soon. Edit: I hope the emote in my last post didn't give mixed messages; the problem is on some forums images get put in the wrong place at random sometimes. Probably just Firefox 2 or something, but I simply clicked on the emote I wanted to put without looking at alt text just to make sure. It was meant to be the "???" emote.
__________________
Last edited by shibbythestoner; 09-15-2007 at 09:08 AM. |
|
|||||
|
Thank very much V0id! Your suggestions helped make my program work! I still have some bugs to fix and perhaps features to add, but this is pretty much it now : Code:
#include <iostream>
#include <fstream>
#include <ctime>
#include <string>
using namespace std;
string writeyn, title, bgcolour, pagealign, txtalign, fontface, fontcolour, imgsrc, alt, linetxt, imgyn, openyn, againyn;
int bgc, stored, pal, imgpos, txal, fontf, fontc, linenum;
int main() {
system("title HTML Writer");
srand(time (0));
cout<<endl;
cout<<"<HTML Writer!>"<<endl;
cout<<"Welcome."<<endl;
cout<<endl;
cout<<"Please remember that when you save a file in HTML Writer, it overwrites the last file with the same file name."<<endl;
cout<<"If you have a previous webpage with the same name that you want to keep, please copy or rename it to preserve it."<<endl;
cout<<"When you are ready please hit [Enter] to continue..."<<endl;
cin.get();
system("cls");
int quit = 0;
cout<<"Modify file? [Y/N] : ";
getline(cin, writeyn);
if (writeyn == "Y" || writeyn == "y") { }
else {
return 0;
}
while (quit != 1) {
ofstream myFile("htmlwriter.htm");
myFile<<"<html>"<<endl;
myFile<<"<head>"<<endl;
myFile<<"<title>";
cout<<"File created."<<endl;
cout<<endl;
cout<<"What would you like as a title for your page?"<<endl;
cout<<"Title : ";
getline (cin, title);
myFile<<title<<"</title>"<<endl;
myFile<<"</head>"<<endl;
cout<<"Title entered."<<endl;
cout<<"Hit [Enter] to continue...";
cin.get();
system("cls");
cout<<endl;
cout<<"What colour would you like your file's background to be? -"<<endl;
cout<<endl;
cout<<"[1] White"<<endl;
cout<<"[2] Black"<<endl;
cout<<"[3] Green"<<endl;
cout<<"[4] Red"<<endl;
cout<<"[5] Blue"<<endl;
cout<<"[6] Yellow"<<endl;
cout<<endl;
cout<<"[7] Advanced settings..."<<endl;
cout<<"[0] Randomise!"<<endl;
cout<<endl;
cout<<"Colour -"<<endl;
cout<<"[1/2/3/4/5/6/7/0] : ";
cin>> bgc;
switch (bgc) {
case 1 :
(bgcolour = "white");
break;
case 2 :
(bgcolour = "black");
break;
case 3 :
(bgcolour = "green");
break;
case 4 :
(bgcolour = "red");
break;
case 5 :
(bgcolour = "blue");
break;
case 6 :
(bgcolour = "yellow");
break;
case 7 :
cout<<"Advanced settings"<<endl;
cout<<endl;
cout<<"[8] Specify a different colour"<<endl;
cout<<"[9] Use a background image"<<endl;
cout<<endl;
cout<<"Specify : ";
cin>> bgc;
if (bgc == 8) {
cout<<"Colour : ";
cin>> bgcolour;
}
else if (bgc == 9) {
cout<<"Is the file stored online or on your computer? -"<<endl;
cout<<endl;
cout<<"[1] Hosted on the internet"<<endl;
cout<<"[2] Stored locally on your computer"<<endl;
cout<<endl;
cout<<"Stored [1/2] : ";
cin>> stored;
if (stored == 1) {
cout<<"Please give the exact URL (address) of the file."<<endl;
cout<<"URL : ";
cin>> bgcolour;
}
else if (stored == 2) {
cout<<"Please copy the image to the same directory (folder) that this program and htmlwriter.htm are stored."<<endl;
cout<<"Then give just the filename of the image you want to use."<<endl;
cout<<"File : ";
cin>> bgcolour;
}
else {
cout<<"Error. Background set to white."<<endl;
}
}
else {
cout<<"Error. Background set to white."<<endl;
}
break;
case 0 :
cout<<"Randomising..."<<endl;
int randombg;
(randombg = 1 + rand() % 6);
switch (randombg) {
case 1 :
(bgcolour = "white");
break;
case 2 :
(bgcolour = "black");
break;
case 3 :
(bgcolour = "green");
break;
case 4 :
(bgcolour = "red");
break;
case 5 :
(bgcolour = "blue");
break;
case 6 :
(bgcolour = "yellow");
break;
default :
cout<<"Error. Bsckground set to white."<<endl;
break;
}
default :
cout<<"Error. Background set to white."<<endl;
break;
}
if (bgc == 9) {
myFile<<"<body background='"<<bgcolour<<"'>"<<endl;
}
else {
myFile<<"<body bgcolor='"<<bgcolour<<"'>"<<endl;
}
cout<<"Background : "<<bgcolour<<""<<endl;
cout<<"Finished setting background."<<endl;
cout<<"Hit [Enter] to continue...";
cin.get();
system("cls");
cout<<endl;
cout<<"How would you like to align your page? -"<<endl;
cout<<endl;
cout<<"|| [1] Left || [2] Centre || [3] Right ||"<<endl;
cout<<endl;
cout<<"Align page -"<<endl;
cout<<"[1/2/3] : ";
cin>> pal;
switch (pal) {
case 1 :
(pagealign = "left");
break;
case 2 :
(pagealign = "center");
break;
case 3 :
(pagealign = "right");
break;
default :
cout<<"Error."<<endl;
(pagealign = "center");
cout<<"Page alignment set to centre."<<endl;
break;
}
myFile<<"<div align='"<<pagealign<<"'>"<<endl;
cout<<"Page alignment : "<<pagealign<<""<<endl;
cout<<"Finished setting alignment."<<endl;
cout<<"Hit [Enter] to continue..."<<endl;
cin.get();
cout<<"Would you like to insert an image into your page? [Y/N] : ";
getline(cin, imgyn);
cout<<endl;
if (imgyn == "y" || imgyn == "Y") {
cout<<"If the file is hosted on the internet, please enter the entire address."<<endl;
cout<<"If it is stored locally on your computer, please copy it to the same directory (folder) as htmlwriter.htm."<<endl;
cout<<"Then simply put the file name (not the entire address)."<<endl;
cout<<"Remember to include the file extension."<<endl;
cout<<endl;
cout<<"File : ";
getline (cin, imgsrc);
cout<<"Alternative text : ";
getline (cin, alt);
cout<<"Hit [Enter] to continue...";
cin.get();
system("cls");
cout<<endl;
cout<<"Where would you like to position your image? -"<<endl;
cout<<endl;
cout<<"[1] To the left"<<endl;
cout<<"[2] At the top"<<endl;
cout<<"[3] To the right"<<endl;
cout<<endl;
cout<<"Position -"<<endl;
cout<<"[1/2/3] : ";
cin>> imgpos;
myFile<<"<table border='0' cellpadding='0' cellspacing='2'>"<<endl;
switch (imgpos) {
case 1 :
myFile<<"<tr>"<<endl;
myFile<<"<td>"<<endl;
myFile<<"<div align='center'>"<<endl;
myFile<<"<img src='"<<imgsrc<<"' alt='"<<alt<<"'>"<<endl;
myFile<<"</div>"<<endl;
myFile<<"</td>"<<endl;
myFile<<"<td align='top'>"<<endl;
cout<<"Image insterted."<<endl;
break;
case 2 :
myFile<<"<tr>"<<endl;
myFile<<"<td valign='top'>"<<endl;
myFile<<"<div align='center'>"<<endl;
myFile<<"<img src='"<<imgsrc<<"' alt='"<<alt<<"'>"<<endl;
myFile<<"<p>"<<endl;
myFile<<"</div>"<<endl;
cout<<"Image inserted."<<endl;
break;
case 3 :
cout<<"The image will be inserted later."<<endl;
break;
default :
cout<<"Error."<<endl;
(imgpos = 1);
myFile<<"<tr>"<<endl;
myFile<<"<td>"<<endl;
myFile<<"<div align='center'>"<<endl;
myFile<<"<img src='"<<imgsrc<<"' alt='"<<alt<<"'>"<<endl;
myFile<<"</div>"<<endl;
myFile<<"</td>"<<endl;
myFile<<"<td valign='top'>"<<endl;
cout<<"Image inserted to the left."<<endl;
break;
}
}
else {
cout<<"No image was used."<<endl;
}
cout<<"Hit [Enter] to continue...";
cin.get();
system("cls");
cout<<endl;
cout<<"Time to configure text settings."<<endl;
cout<<endl;
cout<<"How would you like to align your text? -"<<endl;
cout<<endl;
cout<<"|| [1] Left || [2] Centre || [3] Right ||"<<endl;
cout<<endl;
cout<<"Align -"<<endl;
cout<<"[1/2/3] : ";
cin>> txal;
switch (txal) {
case 1 :
(txtalign = "left");
break;
case 2 :
(txtalign = "center");
break;
case 3 :
(txtalign = "right");
break;
default :
cout<<"Error."<<endl;
(txal = 1);
(txtalign = "left");
cout<<"Alignment set to : left"<<endl;
break;
}
if (imgyn != "y" && imgyn != "Y") {
myFile<<"<table border='0' cellpadding='0' cellspacing='2'>"<<endl;
myFile<<"<tr>"<<endl;
myFile<<"<td valign='top'>"<<endl;
myFile<<"<div align='"<<txtalign<<"'>"<<endl;
}
else {
switch (imgpos) {
case 1 :
myFile<<"<div align='"<<txtalign<<"'>"<<endl;
|