I\'m having trouble with my code below. Any help would be appreciated. #include
ID: 3599056 • Letter: I
Question
I'm having trouble with my code below. Any help would be appreciated.
#include <iostream>
#include <cstdarg>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <ostream>
using namespace std;
void functionjoke (fstream &);
void functionpunchline (fstream &);
int main ()
{
fstream jokefile, punchlinefile;
jokefile.open ("jokes.txt", ios::in);
if (jokefile.fail)
{
cout << "Error printing joke file";
}
functionjoke(jokefile);
jokefile.close();
cout << "/n /n /n";
punchlinefile.open ("punch.txt", ios::in);
if (punchlinefile.fail())
{
cout << "Error opening file /n /n";
}
functionpunchline (punchlinefile);
punchlinefile.close();
system("PAUSE");
return 0;
}
void functionjoke (fstream &)
{
char ch;
file.get(ch);
while (!file.fail())
{
cout << ch;
file.get(ch);
}
cout << "/n";
}
void functionpunchline (fstream &)
{
int i = 3;
char ch;
char line [30];
file.seekg(0L, ios::end);
file.seekg(-3L, ios::end);
ch = file.get();
while (ch!= "/n")
{
file.seekg(-i, ios::end);
ch = file.get ();
i++;
}
file.getline (line, i);
}
Explanation / Answer
i have corrected the errors and highlighted statements
#include <iostream>
#include <cstdarg>
#include <cstdlib>
#include <istream>
#include <fstream>
#include <ostream>
using namespace std;
void functionjoke (fstream &);
void functionpunchline (fstream &);
int main ()
{
fstream jokefile, punchlinefile;
jokefile.open ("jokes.txt", ios::in);
if (jokefile.fail())
{
cout << "Error printing joke file";
}
functionjoke(jokefile);
jokefile.close();
cout << "/n /n /n";
punchlinefile.open ("punch.txt", ios::in);
if (punchlinefile.fail())
{
cout << "Error opening file /n /n";
}
functionpunchline (punchlinefile);
punchlinefile.close();
system("PAUSE");
return 0;
}
void functionjoke (fstream &file)
{
char ch;
file.get(ch);
while (!file.fail())
{
cout << ch;
file.get(ch);
}
cout << "/n";
}
void functionpunchline (fstream &file)
{
int i = 3;
char ch;
char line [30];
file.seekg(0L, ios::end);
file.seekg(-3L, ios::end);
ch = file.get();
while (ch!= ' ')
{
file.seekg(-i, ios::end);
ch = file.get ();
i++;
}
file.getline (line, i);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.