PigLatin Program HELP!

This is a discussion on PigLatin Program HELP! within the C Programming forums, part of the General Programming Boards category; This is what I have for my piglatin word translator program so far, there's an error C2059 in the Rule1 ...

  1. #1
    Registered User
    Join Date
    Jul 2012
    Posts
    5

    PigLatin Program HELP!

    This is what I have for my piglatin word translator program so far, there's an error C2059 in the Rule1 function where firstletter[1] and firstletter[2] are. Can someone help me with this? Also you don't have to do this but if you want it would be greatly appreciated if you looked at the entire program and gave me some tips PS its still a work in progress
    Code:
    // PigLatin Word Converter
    // James Le
    // COP2220 Summer 2012
    
    
    #define _CRT_SECURE_NO_DEPRECATE
    #include<stdio.h>
    #include <math.h>
    #include <string.h>
    
    
    
    
    
    
    void Instructions (); // Function that defines instructions
    
    
    void UserInput(); // Function that gets the input from the user and stores it somewhere
    
    
    void terminate(); // Function to either continue or quit the program
    
    
    int RuleChoice(char); // Function to determine which rule applies
    
    
    int Rule1(char); // Function for Rule 1 for pig latin
    
    
    int Rule2 (char); // Function for rule 2 for pig latin
    
    
    int Rule3(char); // Function for rule 2 for pig latin
    
    
    void Display(char); // Function to display final word onto screen
    
    
    void AY( int /*don't know if i need an int for now*/ );
    
    
    
    
    //char input_string [100];
    
    
    //char*x = input_string;
    
    
    
    
    
    
    int main()
    {
    	char input_string[100];
    	char *str1, *str2;
    	str1=input_string;
    
    
    	/*FILE*PigLatin;
    	PigLatin = fopen ("piglatin.txt", "a");*/
    
    
    	Instructions();
    	//printf("Enter a word:");
    	printf("Enter a word: ");
    	scanf("\n%s", input_string);
    	
    	if(RuleChoice(str1)==1)
    	{
    		Rule1(str1);
    	}
    	else if(RuleChoice(str1)==2)
    	{
    		Rule2(str1);
    	}
    	else
    	{
    		Rule3(str1);
    	}
    
    
    	//UserInput();
    	//UserInput(); FUNCTION NEEDS WORK//
    	
    	
    	
    
    
    	getchar();
    	return 0;
    }
    
    
    void Instructions()
    {
    	printf("Welcome to the PigLatin Converter\n");
    	printf("You will enter a word\n");					// General Instructions to the program where it tells the user they will be entering a word to be converted to pig latin
    	printf("The word will be converted to PigLatin\n");
    	//UserInput();
    	//Display();
    	//terminate();
    	
    }
    
    
    /*void UserInput() // return a pointer to an array to avoid ........
    {
    	FILE *PigLatin;
    	
    	PigLatin = fopen ("piglatin.txt", "w");
    
    
    	//printf("Enter a word: ");
    	//scanf("\n%s", input_string);
    	//fprintf(PigLatin, "%s", input_string);
    	
    	RuleChoice();
    
    
    	fclose(PigLatin);
    
    
    	getchar();
    }
    */
    
    
    void Display(char *str1) // This function will display the new word that the program has converted into pig latin.
    					// The function passes in a char and doesn't return anything, just prints the word
    {
    	printf("The word you enter is %s\n", *str1);
    	//PigLatin=fopen("piglatin.txt", "w");
    	//fprintf(PigLatin,"%s");
    		//fprintf(PigLatin, "%s", input_string);
    
    
    }
    
    
    
    
    void terminate() // Function to Terminate Program
    				// The function doesn't require a variable to pass into it
    				// The program declares its own local variable choice and runs a while loop
    {
    	int choice;
    	printf("\nTo quit program enter 0:\n");
    	printf("\nTo continue program enter 1:\n");
    	scanf("%d", &choice);
    
    
    	while(choice == 1) // if the choice is '1', the function will return the user to the instructions where they will be prompted for another word
    	{
    		//void Instructions();
    		Instructions();
    	}
    	
    }
    
    
    
    
    int RuleChoice( char *str1 ) // Function to determine which rule applies to word
    						// If the function compares the first two rules and they don't apply it will automatically default to Rule 3.
    {
    	char Rule1[]={'H'}; //Still has to account for the QU
    	char Rule1Q	[]="Qu";				// Checks the word to see if the second letter is an 'H' and .....
    
    
    	char Rule2[]={'A', 'E', 'I', 'O', 'U'}; // Character array that checks if the word begins with a vowel
    
    
    
    
    	if (str1[0]==Rule1[0] || (str1[0]==Rule1Q[0] && str1[1]==Rule1Q[1])) // If the second element of the array is an 'H' or the first two elements are a 'Qu' then rule 1 applies
    	{
    		printf("Rule 1");
    		return 1;
    	}
    	
    	else if (str1[0]==Rule2[0]||Rule2[1]||Rule2[2]||Rule2[3]||Rule2[4]) // If the first element of the input_string is a vowel then rule 2 applies
    	{
    		return 2;
    	}
    
    
    	else // If both fail, default to rule 3
    	{
    		return 3;
    	}
    }
    
    
    
    
    int Rule1(char *str1) // Rule 1 Function
    {
    	char return_string[100];
    
    
    	char erase[2] = {' ', ' '}; 
    
    
    	char firstletter[3];// stores the first element of the input string to be used later
    	
    	firstletter[0] = str1[0];// stores the first element of the input string to be used later
    	firstletter[1] = {'A'};
    	firstletter[2] = {'Y'};
    	
    	strncpy(str1, erase,2); // eliminates the first two letters of the word and replaces with blanks of the erase array
    	
    	strcat(str1, firstletter); // concatenates the original first letter and 'AY' to the end of the word
    
    
    	Display(str1); // displays new word onto screen
    }
    
    
    int Rule2(char *str1) // Rule 2 function
    {
    	
    	//char AY[2]={'A','Y'};
    	
    		//if(input_string[0] == 'A' || input_string[0] == 'a' || input_string[0] == 'E' || input_string[0] == 'e' || input_string[0] == 'I' || input_string[0] == 'i' || input_string[0] == 'O' || input_string[0] == 'o' || input_string[0] == 'U' || input_string[0] == 'u') 
    			
    				strcat(str1, "AY"); // simply adds AY to the end of the word
    				Display(str1); // Displays new word
    				getchar();
    			
    
    
    
    
    	}
    
    
    
    
    /*if(U_Input = Rule2Str1 || U_Input = Rule2Str1L)
    {
    	strcat(U_Input, 'AY');
    }
    
    
    else if //...........
    {
    }*/
    
    
    
    
    
    
    int Rule3(char *str1) // Function for rule 3 of piglatin which accepts the input_string character array displays the new word
    {
    	char AY[2]={'A','Y'};
    	char erase [2] = {' '};
    	str1[(strlen(str1)+1)]==str1[0]; // takes first element of string and sets it equal to element that is one more than the length of the word
    	
    	strncpy(str1, erase, 2); //erases the first letter and puts a blank space in the element
    
    
    	strcat(str1, AY); //adds AY to the end of the word
    
    
    	Display(str1); // Displays new word in pig latin
    
    
    	getchar();
    
    
    }

  2. #2
    Registered User
    Join Date
    May 2009
    Posts
    2,579
    Instead of

    Code:
        firstletter[1] = {'A'};
        firstletter[2] = {'Y'};
    Try
    Code:
        firstletter[1] = 'A';
        firstletter[2] = 'Y';
    Tim S.
    "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the Universe is winning." Rick Cook

  3. #3
    Registered User
    Join Date
    Jul 2012
    Posts
    5
    ok wow I feel like an idiot :P

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 13
    Last Post: 11-03-2010, 12:45 PM
  2. Replies: 1
    Last Post: 03-03-2009, 03:47 PM
  3. Replies: 5
    Last Post: 08-16-2007, 11:43 PM
  4. Replies: 18
    Last Post: 11-13-2006, 12:11 PM
  5. pigLatin, code prints funny characters
    By Nutshell in forum C Programming
    Replies: 16
    Last Post: 01-23-2002, 07:33 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21