Converting text to Pig Latin issue

Hi, I'm sort of new to C++, and need to write a code that converts text from an input file to pig latin and outputs it to another output file. I've written the code, but I keep running into issues, and I was wondering if anyone could help me. I keep getting something about the stack of the variable "word", and I don't know what it means. If you could help me it'd be great!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
N Bonzani
Lab 4 Problem 1
2/5/13

Write a program that reads in a text file 
and converts it to pig Latin.  i.e. if the 
first letter is a consonant, move it to the 
end and add “ay” to the end, if it is a 
vowel add “way” to the end.  Here’s an 
example:  “end the war” becomes “endway 
hetay arway”.  Include a structure chart.
*/

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

bool check(char word[200]);
void vowel (char word[]);
void consonant(char word[]);
int main()
{
	ifstream in;
	char filename[200];
	cout<< "Enter name of input file: ";
	cin.getline(filename,200);
	in.open(filename);
	ofstream out;
	char outname[200];
	cout<< "Enter name of output file: ";
	cin.getline(outname, 200);
	out.open(filename);
	if(!in.is_open())
	{
		cout<<"ERROR failed to open input file " << filename << " BYE\n";
		exit(-1);
	}
	if(!out.is_open())
	{
		cout<<"ERROR failed to open output file " << filename << " BYE\n";
		exit(-1);
	}
	char word[200];
	bool result;
	while(!in.eof())
	{
		in>>word;
		result=check(word);
		if(result==true)
			vowel(word);
		else
			consonant(word);
		out<< word;

	}
}

bool check(char word[200])
{
	if(word[0]=='a'|| word[0]=='e'|| word[0]=='i'|| word[0]=='o'|| word[0]=='u'|| word[0]=='A'|| word[0]=='E'|| word[0]=='I'|| word[0]=='O'|| word[0]=='U')
		return true;
	else
		return false;
}

void vowel (char word[])
{
	int last(0);
	last=strlen(word);
	word[last]='w';
	word[last+1]='a';
	word[last+2]='y';
	word[last+3]='\0';

}

void consonant(char word[])
{
	int last;
	char temp='\0';
	last=strlen(word);
	word[0]=temp;
	for(int i=1;i<last-1;i++)
	{
		char tem=word[i];
		word[i]=word[i+1];
		word[i-1]=tem;
	}
	word[last-1]=temp;
	word[last]='a';
	word[last+1]='y';
	word[last+2]='\0';
}
http://www.cplusplus.com/forum/beginner/91945/
Class assignment?

Anyway, please copy and paste the exact compiler errors you're getting.
Last edited on
It is a school assignment but it looks like ours are different. (I don't have the same rules of pig latin that the other poster does, his are a bit more strict.) And I'm not getting compiler errors but rather a pop up that occurs after I input both the input and output file names. It gives me the option to retry, abort, or cancel.
It gives me the option to retry, abort, or cancel.


It also tells you why it's giving you those options.

1
2
	in.open(filename);
	out.open(filename);


When you open the same file for output as you do input, you truncate the file. When you read data from in, the file is empty and you don't actually read anything in. Tip: Looping on eof is rarely the right thing to do.

The following is better:
1
2
3
4
5
6
7
8
9
10
	while(in>>word)
	{
		result=check(word);
		if(result==true)
			vowel(word);
		else
			consonant(word);
		out<< word;
	}
Oh man, wow. I feel like an idiot. I didn't notice I had the wrong variable in the out.open function. It actually fixed everything. Thanks!
Topic archived. No new replies allowed.