Thread: Pig Latin problem

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    4

    Angry Pig Latin problem

    I have to write this pig latin program for my class and for some reason it's not working. I'm almost done, just debugging now. If anyone could tell me what's wrong...that'd be appreciated...thanx.

    Code:
    #include<fstream.h>
    
    void main (void)
    {
    	ifstream inputfile;
    	ofstream outputfile;
    	const int limit = 99;
    	int i, vowel_place;
    	char sentence[limit];
    	char char1;
    
    	inputfile.open("Input.txt");
    	outputfile.open("Output.txt");
    	i = 0;
    	inputfile.getline(sentence, limit);
    
    	while (!inputfile.eof())
    	{
    		if (!inputfile)
    			break;
    
    		inputfile.getline(sentence, limit);
    		while (sentence[i] == '\0')
    		{
    			 if (sentence[i] != '\0' && (sentence[i] == ' ' || sentence[i] == ',' || sentence[i] == '.' || sentence[i] == '?' || sentence[i] == '!' || sentence[i] == '-'))
    			 {
    				 outputfile << sentence[i];
    			 }
    			 else
    			 {
    				 if (sentence[i] != '\0' && (sentence[i] == 'a' || sentence[i] == 'e' || sentence[i] == 'i' || sentence[i] == 'o' || sentence[i] == 'u' || sentence[i] == 'A' || sentence[i] == 'E' || sentence[i] == 'I' || sentence[i] == 'O' || sentence[i] == 'U'))
    					{
    					  while (sentence[i] != '\0' && (sentence[i] == ' ' || sentence[i] == ',' || sentence[i] == '.' || sentence[i] == '?' || sentence[i] == '!' || sentence[i] == '-'))
    						{
    						 outputfile << sentence[i];
    							 i++;
    						}
    							 outputfile << "ay" << sentence[i];
    						}
    				 else
    				 {
    
    						if (sentence[i] != '\0')
    							{
    								char1 = sentence[i];
    								i++;
    
    								while (sentence[i] != '\0' && (sentence[i] == ' ' || sentence[i] == ',' || sentence[i] == '.' || sentence[i] == '?' || sentence[i] == '!' || sentence[i] == '-'))
    									{
    										outputfile << sentence[i];
    										i++;
    									}
    								outputfile << char1 << "ay" << sentence[i];
    							}
    						}
    				  }
    			}
    		}
    		cout << outputfile;
    		inputfile.close();
    		outputfile.close();
    }
    If anyone has any questions...e-mail me @ [email protected]

  2. #2
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    What is it doing and what is it supposed to do?

  3. #3
    Registered User
    Join Date
    Nov 2002
    Posts
    4

    purpose of program

    the purpose is to convert a string from english to pig latin in input.txt

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    126
    well, if my understanding of pig latin is correct, you take the first letter or combination of letters that make a unique sound off the front of the word, then you say the fragment of the original word and the first letter(s) + "ay". I'd think that program would be quite a bit more complex than you have made it because you will have to deal with special combinations of letters like "sh" or "ch" or "ph". You probably should re-think the way that you parse each individual word out of the file too, because it looks to me like the way you've written it there wouldn't work well at all. The way I would do it is get the size of the file and then read the whole friggin file into a buffer with file.read(), I have found that this method is much more reliable than that stupid getline function. Also, each word(unless it is the first on the line) will pretty much always come after a space, a newline, a tab, or some type of quote. You should probably base your word parser on this. Hope this helps a litle bit.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 08:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 06:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM