String class to C string class

Having a little trouble with my assignment in my C++ class. I was assigned to write a program that displays an mad lib and asks questions to fill in the blanks of the mad lib. I have posted my current program below but my professor has informed me that I cant use string class and can only use c string class. If you could tell me how to change the code below to replace all the string class with c-string class it would be much appreciated. Thanks.

#include <iostream>
#include <string>
#include <fstream>
using namespace std;

void getFilename(char fileName[])
{
cout << "Please enter the filename of the Mad Lib: ";
cin >> fileName;
return;
}

bool read(char fileName[], string nounPlural, string typeOfliquid, string nounPlural2, string adjective, string funnyNoise, string adjective2, string funnyNoise2, string animal, string animal2)
{
ofstream fout(fileName);

fout << "Zoos are places where wild " << nounPlural << " are kept in pens or cages\n";
fout << "so that " << nounPlural2 << " can come and look at them. ";
fout << "There is a zoo\nin the park beside the " << typeOfliquid << " fountain. When it is feeding time,\n";
fout << "all the animals make " << adjective << " noises. The elephant goes \"" << funnyNoise << "\"\n";
fout << "and the turtledoves go \"" << funnyNoise2 << ".\" My favorite animal is the\n";
fout << adjective2 << " " << animal << ", so fast it can outrun a/an " << animal2 << ".\n";
fout << "You never know what you will find at the zoo.\n";

fout.close();
return true;
}

void askQuestions(string &nounPlural, string &typeOfliquid, string &nounPlural2, string &adjective, string &funnyNoise, string &adjective2, string &funnyNoise2, string &animal, string &animal2)
{


cout << "\tPlural noun: ";
cin >> nounPlural;
cout << "\tPlural noun: ";
cin >> nounPlural2;
cout << "\tType of liquid: ";
cin >> typeOfliquid;
cout << "\tAdjective: ";
cin >> adjective;
cout << "\tFunny noise: ";
cin >> funnyNoise;
cout << "\tAnother funny noise: ";
cin >> funnyNoise2;
cout << "\tAdjective: ";
cin >> adjective2;
cout << "\tAnimal: ";
cin >> animal;
cout << "\tAnother animal: ";
cin >> animal2;

}

void displayFile(string nounPlural, string typeOfliquid, string nounPlural2, string adjective, string funnyNoise, string adjective2, string funnyNoise2, string animal, string animal2)
{
cout << "Zoos are places where wild " << nounPlural << " are kept in pens or cages\n";
cout << "so that " << nounPlural2 << " can come and look at them. ";
cout << "There is a zoo\nin the park beside the " << typeOfliquid << " fountain. When it is feeding time,\n";
cout << "all the animals make " << adjective << " noises. The elephant goes \"" << funnyNoise << "\"\n";
cout << "and the turtledoves go \"" << funnyNoise2 << ".\" My favorite animal is the\n";
cout << adjective2 << " " << animal << ", so fast it can outrun a/an " << animal2 << ".\n";
cout << "You never know what you will find at the zoo.\n";
}

int main()
{
string nounPlural;
string typeOfliquid;
string nounPlural2;
string adjective;
string funnyNoise;
string adjective2;
string funnyNoise2;
string animal;
string animal2;

char fileName[256];
getFilename(fileName);

askQuestions(nounPlural, typeOfliquid, nounPlural2, adjective, funnyNoise, adjective2, funnyNoise2, animal, animal2);


if (!read(fileName, nounPlural, typeOfliquid, nounPlural2, adjective, funnyNoise, adjective2, funnyNoise2, animal, animal2))
{
cout << "Error reading file " << fileName << endl;
return 1;
}

cout << endl;

displayFile(nounPlural, typeOfliquid, nounPlural2, adjective, funnyNoise, adjective2, funnyNoise2, animal, animal2);

return 0;
}
Okay I think I figured it out. I just erased all the "string" syntax, replaced it with char and where they were declared in main I made them all [256] in length (not sure if that is needed). I also had to take out all the pass by references in the askQuestions function. Also took out the string library obviously. Below is the newly formatted program, let me know if you would change anything to make it more efficient. Thanks.

void getFilename(char fileName[])
{
cout << "Please enter the filename of the Mad Lib: ";
cin >> fileName;
return;
}


bool read(char fileName[], char nounPlural[], char typeOfliquid[], char nounPlural2[], char adjective[], char funnyNoise[], char adjective2[], char funnyNoise2[], char animal[], char animal2[])
{
ofstream fout(fileName);





fout << "Zoos are places where wild " << nounPlural << " are kept in pens or cages\n";
fout << "so that " << nounPlural2 << " can come and look at them. ";
fout << "There is a zoo\nin the park beside the " << typeOfliquid << " fountain. When it is feeding time,\n";
fout << "all the animals make " << adjective << " noises. The elephant goes \"" << funnyNoise << "\"\n";
fout << "and the turtledoves go \"" << funnyNoise2 << ".\" My favorite animal is the\n";
fout << adjective2 << " " << animal << ", so fast it can outrun a/an " << animal2 << ".\n";
fout << "You never know what you will find at the zoo.\n";




fout.close();
return true;
}

void askQuestions(char nounPlural[], char typeOfliquid[], char nounPlural2[], char adjective[], char funnyNoise[], char adjective2[], char funnyNoise2[], char animal[], char animal2[])
{


cout << "\tPlural noun: ";
cin >> nounPlural;
cout << "\tPlural noun: ";
cin >> nounPlural2;
cout << "\tType of liquid: ";
cin >> typeOfliquid;
cout << "\tAdjective: ";
cin >> adjective;
cout << "\tFunny noise: ";
cin >> funnyNoise;
cout << "\tAnother funny noise: ";
cin >> funnyNoise2;
cout << "\tAdjective: ";
cin >> adjective2;
cout << "\tAnimal: ";
cin >> animal;
cout << "\tAnother animal: ";
cin >> animal2;

}

void displayFile(char nounPlural[], char typeOfliquid[], char nounPlural2[], char adjective[], char funnyNoise[], char adjective2[], char funnyNoise2[], char animal[], char animal2[])
{
cout << "Zoos are places where wild " << nounPlural << " are kept in pens or cages\n";
cout << "so that " << nounPlural2 << " can come and look at them. ";
cout << "There is a zoo\nin the park beside the " << typeOfliquid << " fountain. When it is feeding time,\n";
cout << "all the animals make " << adjective << " noises. The elephant goes \"" << funnyNoise << "\"\n";
cout << "and the turtledoves go \"" << funnyNoise2 << ".\" My favorite animal is the\n";
cout << adjective2 << " " << animal << ", so fast it can outrun a/an " << animal2 << ".\n";
cout << "You never know what you will find at the zoo.\n";
}

int main()
{
char nounPlural[256];
char typeOfliquid[256];
char nounPlural2[256];
char adjective[256];
char funnyNoise[256];
char adjective2[256];
char funnyNoise2[256];
char animal[256];
char animal2[256];

char fileName[256];
getFilename(fileName);

askQuestions(nounPlural, typeOfliquid, nounPlural2, adjective, funnyNoise, adjective2, funnyNoise2, animal, animal2);


if (!read(fileName, nounPlural, typeOfliquid, nounPlural2, adjective, funnyNoise, adjective2, funnyNoise2, animal, animal2))
{
cout << "Error reading file " << fileName << endl;
return 1;
}

cout << endl;

displayFile(nounPlural, typeOfliquid, nounPlural2, adjective, funnyNoise, adjective2, funnyNoise2, animal, animal2);









return 0;
}


Topic archived. No new replies allowed.