Issues making a Mad Lib

I'm trying to make a Mad Lib program for my intro to programming class. It's a little different from the other ones that I've seen tutorials for online because the assignment is to receive the body of the story and the prompts from a file. This requires passing arrays of strings and whatnot. The problems that I'm running into is that every input that I put in is loosing the first letter except for the first one and I'm getting some random buggy looking characters before my play again prompt (which also isn't working for some reason). Any input would be amazingly helpful! Thank you so much.

[code]
#include <iostream>
#include <fstream>
#include <cctype>
using namespace std;
int readFile(char filename[], char story[][32]);
void askQuestions(char story[]);
char playAgain(char response);
void display(char story[][32]);

int main()
{
// Set variables for the functions
char response;
char filename[256];
char story[256][32];
// Set loop to repeat game whenever the user answers ye to play again
do
{
// Prompt the user for a filename
cout << "Please enter the filename of the Mad Lib: ";
cin >> filename;
// Call the function to read the file
int numWords = readFile(filename, story);
// Display the Mad Lib
display(story);
// Ask if they want to play again
char response = playAgain(response);
}
while ( response == 'y' || response == 'Y');
cout << "Thanks for playing.\n";
return 0;
}

int readFile(char filename[], char story[][32])
{
// Open the file
ifstream fin(filename);

// Fail message
if ( fin.fail())
{
cout << "Unable to open " << filename << endl;
return -1;
}

// Do work
int numWords = 0;
while ( numWords < 256 && fin >> story[numWords])
{
if (story[numWords][0] == '<' && !ispunct(story[numWords][1]))
askQuestions(story[numWords]);
numWords++;
}

// Close file and return
fin.close();
return numWords;
}

void askQuestions(char story[])
{
// Standard FOR loop to read through story
for ( int iStory = 1; story[iStory]; iStory++)
{
// Set specialCase to true when there is a non-prompt token
// Also put a tab before the first character and set it to
// upper case
if ( story[iStory - 1] == '<')
{
cout << "\t" << (char)toupper(story[iStory]);
}
// Skip a space whenever an underscore is encountered
else if (story[iStory] == '_')
{
cout << " ";
}
// Put text from story onto the screen
else if ( story[iStory] == '>')
{
// Put a colon and a space following the text and
// receive input from the user when a special
// character was not encountered
cout << ": ";
cin.ignore();
cin.getline(story, 256);
}
else
{
cout << (char)tolower(story[iStory]);
}
}
}

char playAgain(char response)
{
cout << "Play again? (y/n) ";
cin >> response;
return response;
}

void display(char story[][32])
{
// Standard FOR loop to read through story. Start at 1 to skip the first
// letter.
for ( int iStory = 0; story[iStory][0]; iStory++)
{
if ( story[iStory][1] == '#')
cout << endl;
else if ( story[iStory][1] == '{')
cout << "\"";
else if ( story[iStory][1] == '}')
cout << "\"";
else if ( story[iStory][1] == '[')
cout << "'";
else if ( story[iStory][1] == ']')
cout << "'";
else if ( story[iStory][0] == '.')
{
cout << ".";
}
else if ( story[iStory][0] == ',')
{
cout << ",";
}
else
{
cout << " " << story[iStory];
}
}
}

Topic archived. No new replies allowed.