one major improvement is to stop using Turbo C++ and use any latest compiler!!
i am shocked to know even big companies use Turbo C for training purposes, and no emphasis on coding style or C standards at all !!!!!
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
void initialize(char[],char[]);
void readinput(char english[]);
int countwords(char english[]);
void convert(int words, char english[], char piglatin[]);
void writeoutput(char piglatin[]);
int main()
{
char english[80], piglatin[80];
int words;
printf("Welcome to the Piglatin Generator\n\n");
printf("Type \'END\'when finished\n\n");
do {
/*process a new line of text*/
initialize(english, piglatin);
printf("now before read input");
readinput(english);
printf("now after read input");
/*count the no of words in the line*/
words=countwords(english);
/*convert english to piglatin*/
printf("now before writeoutput");
writeoutput(piglatin);
break;
}
while(words>=0);
printf("\naveh aa icena ayda (Have a nice day)\n");
}
/*intialize the character arrays with blank spaces*/
void initialize(char english[],char piglatin[])
{
int count;
for(count=0;count<80;++count)
english[count]=piglatin[count]=' ';
}
/*read one line of English text*/
void readinput(char english[])
{
int count=0;
char c;
while(count < 15)
{
c=getchar();
english[count]=c;
++count;
}
printf("now in read input");
return;
}
/*scan the english text and determine the number of words*/
int countwords(char english[])
{
int count, words=1;
for(count=count<79;++count;)
if(english[count]==' '&& english[count+1] !=' ')
++words;
return(words);
}
/*convert each word into piglatin*/
void convert(int words,char english[],char piglatin[])
{
int n, count;
int m1=0;
int m2;
/*convert each word*/
for(n=1;n<=words;++n)
{
/*locate the end of the current word*/
count=m1;
while(english[count]!=' ')
m2=count++;
/*transpoes the first letter and add a*/
for(count=m1;count<m2;++count)
piglatin[count+(n-1)]=english[count+1];
piglatin[m2+(n-1)]=english[m1];
piglatin[m2+n]='a';
/*reset the initial maarker*/
m1=m2+2;
}
return;
}
/*display the line of text in piglatin*/
void writeoutput(char piglatin[])
{
int count=0;
for(count=0;count<80;++count)
putchar(piglatin[count]);
printf("\n");
return;
}
piglatin[count+(n-1)]=english[count+1];
piglatin[m2+(n-1)]=english[m1]
[B]# include <iostream>
#include <string>
using namespace std;
string str;
string pstr;
string piglatin( string pstr);
int main()
{
cout<<"enter the string:"<<endl;
cin>>str;
cout << " The piglatin form of the input string is:"<<piglatin(str)<<endl;
cin.ignore();
cin.get();
return 0;
}
string piglatin(string pstr)
{
string::size_type len=pstr.length();
string rstr;
rstr=pstr.substr(1,len-1)+pstr[0];//[B] [COLOR="Blue"]rotates the string[/COLOR][/B]
pstr = rstr + "ay";
return pstr;
cin.get();
cin.ignore();
}[/B]
@vickybat:There is a small problem with the piglatin concept you used.It's not like the first letter is brought to the end and an 'ay' is added,but its a consonant cluster that is rotated to the end. ie,scram should produce 'amscray' and not 'cramsay' since the first consonant cluster is 'scr'.
Pig Latin is a language game of alterations played in English. To form the Pig Latin form of an English word the first consonant (or consonant cluster) is moved to the end of the word and an ay is affixed (for example, pig yields ig-pay and computer yields omputer-cay). The object is to conceal the meaning of the words from others not familiar with the rules. The reference to Latin is a deliberate misnomer, as it is simply a form of jargon, used only for its English connotations as a "strange and foreign-sounding language."
Why the cin.get() and cin.ignore() in piglatin()? These statements will have no effect, since control is returned before them.
And let me guess their presence in main() is to trap keyboard to see output? You need a better IDE in that case.
And why are you using global variables in the program? They are certainly not needed.
Search the same wikipedia page for the word 'scram'.
pig is igpay because the 2nd letter itself is a vowel(i).So the left of 'i' is rotated.Same with computer o is a vowel.So c alone is there to be rotated.
Similarly in scram ,the left of the firstly found vowel is rotated,ie,the left of a,'scr'.If it was
cjkdkomputer then the piglatin will be omputercjkdkay.