Here's my code so far...
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(char); // 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
char Rule1(char); // Function for Rule 1 for pig latin
char Rule2 (char); // Function for rule 2 for pig latin
char Rule3(char); // Function for rule 2 for pig latin
void Display(char); // Function to display final word onto screen
char AY( char /*don't know if i need an int for now*/ );
int main()
{
char input_string[100];
char *str1, *str2;
str1=input_string;
/*FILE*PigLatin;
PigLatin = fopen ("piglatin.txt", "a");*/
Instructions();
printf("Enter a word: ");
scanf("\n%s", input_string);
UserInput(str1); // stores the input_string into a file
RuleChoice(str1);
if(RuleChoice(str1)==1)
{
Rule1(str1);
}
else if(RuleChoice(str1)==2) // If statements where whatever integer RuleChoice returns will enter the word into the specified Rule function
{
Rule2(str1);
}
else
{
Rule3(str1);
}
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(char *str1) //Stores the input of the user into a file
{
FILE *PigLatin;
PigLatin = fopen ("piglatin.txt", "w"); // Opens a text file called piglatin
char input_string[];
char input_string = *str1;
//printf("Enter a word: ");**ignore** commented out to compile
scanf("\n%s", &input_string);
//fprintf(PigLatin, "%s", input_string);**ignore** commented out to compile
RuleChoice(str1);
fclose(PigLatin);
}
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"); *****************ignore these three comments
//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"); // Simply asks the user if they would like to quit or continue
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();****ignore this line
main(); // Returns back to the beginning of the program
}
}
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
{
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;
}
}
void Rule1(char *str1) // Rule 1 Function
{
char return_string[100];
char erase[2] = {' ', ' '}; // character array that will print blanks == "erase"
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'; **ignore** commented out to compile
//firstletter[2] = 'Y'; **ignore** commented out to compile
strncpy(str1, erase,2); // eliminates the first two letters of the word and replaces with blanks of the erase array
AY(str1); // concatenates the original first letter and 'AY' to the end of the word
Display(str1); // displays new word onto screen
getchar();
main();
}
void Rule2(char *str1) // Rule 2 function accepts the str1 pointer which points to input_string and returns the new piglatin string
{
AY(str1); //Makes call to AY function for concatenation
Display(str1); //Displays new word //char AY[2]={'A','Y'};
//**ignore**//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')
getchar();
main(); //Returns to main
}
void Rule3(char *str1) // Function for rule 3 of piglatin which accepts the pointer str1 to the input_string character array displays the new word
{
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
AY(str1); //Makes call to the AY function
Display(str1); // Displays new word in pig latin
getchar();
main(); // Returns to main
}
char AY (char *str1) //Function that simply concatenates 'AY' to the end of the string at a certain point in the program
{
char AY[]="AY";
strcat(str1,AY);
return *str1;
}
there is an C2143 error where it says i'm missing a ';' at line 87 and 88 and at line 90 is says input string is an undeclared indentifier...
Please help with this! And if you're up to it, if you could look at the entire program to see if it makes sense, that would be greatly appreciated...