As for your error, like the other guy said if isn't a loop, but for is.. so replace all instances. You probably gonna get some variables not declared and some other stuff.
if you need an example:
Code:
#include<iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream input;
char word[25]; // Store user inputed word.
input.open("story.txt"); // Open input file.
input.seekg(0, ios::end); // Detect length of file.
int length = input.tellg(); // Store length.
input.seekg (0, ios::beg); // Go back to beginning of file.
char *story = new char[length]; // Create array large enough to hold entire story.
input.read(story, length); // Store entire story.
input.close(); // Close input file.
ofstream outfile;
outfile.open("Final Story.txt"); // Open output file.
for(int i = 0; i < length; i++) // Go through entire story character by character.
{
if(story[i] != '[') // If '[' not found yet then just output character to file.
outfile << story[i];
else // Else '[' found
{
i++; // move to next letter in story.
cout << "Input a "; // Display to user.
while(story[i] != ']') // While we haven't reached ']' output user request. i.e. Noun.
{
cout << story[i];
i++;
}
cout << "? ";
cin >> word; // User puts in desired word.
outfile << word; // Put that word in the final story.
} // Go through the while loop and process rest of story.
}
outfile.close(); // Close output file.
delete story; // Free memory.
return 0;
}
Input File
Code:
TWas the night before
[Holday]
and all through the
[Noun],
not a
[Noun]
was
[Verb]
,not even your
[Noun].
All the children were tucked all snug in their
[Noun],
with visions of
[Food]
dancing in their heads.The stockings were hung by the chimney with
[Verb],
in hopes that
[Person]
soon would be there.I in my kerchief and ma in her
[Noun],
had just
[Verb]
down for a
[Adjective]
winter's nap.When up on the roof on I
[Verb]
such a
[Adjective]
,I jumped from my bed to
[Verb]
what was the matter.When what do my
[Adjective]
eyes do appear,but a
[Noun]
and eight
[Adjective]
reindeer.
Final output:
Code:
TWas the night before
Valentine'sDay
and all through the
slums,
not a
bum
was
humpin'
,not even your
mum.
All the children were tucked all snug in their
cells,
with visions of
rats
dancing in their heads.The stockings were hung by the chimney with
glee,
in hopes that
MyDrugDealer
soon would be there.I in my kerchief and ma in her
thong,
had just
layed
down for a
short
winter's nap.When up on the roof on I
felt
such a
jolt
,I jumped from my bed to
see
what was the matter.When what do my
wasted
eyes do appear,but a
prostitute
and eight
sexy
reindeer.