hi,
thanks for your help with that program, i actually cleared all the errors, but on executing the program it does not go through the first loop...any ideas??
Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
void translateline(char [], char []);
int extractintoew(char [], char [],int);
void convertintopig(char [], char [] );
int wherevowel(char []);
int copyintopl(char [], char [],int);
int main()
{
char el[100]={'\0'},pl[200]={'\0'};
int a=0;
printf("Please enter a line(# to end): ");
gets(el);
while(el[0]!='#')
{
translateline(el,pl);
puts(pl);
printf("\nPlease enter a line(# to end): ");
fflush(stdin);
gets(el);
}
printf("Good Bye. Oodgay Ebyay\n");
system("PAUSE");
return 0;
}
void translateline(char el[], char pl[])
{
char ew[17]={'\0'},pw[17]={'\0'};
int ep=0,pp=0,k=0,r;
while(el[ep]!='\0')
{
if(isalpha(el[ep]))
{
k=extractintoew(el,ew,ep);
ep+=k;//this is to keep everything at par, so even here, one behind space or punct
convertintopig(ew,pw);//copies the contents of pw into pl, pp at this point is still 0
r=copyintopl(pw,pl,pp);//this will return the value of pp, as to where it is in pl so that we can put the punct or space
pp+=r;//now pp is set at before that point
pp--;//now it is set for pp++
pp++;//now ready to accept punct or space position
ep++;//now at punct or space position
}
else
{
if(isspace(el[ep]))
{
el[ep]=pl[pp];
}
else
{
el[ep]=pl[pp];
strcat(pl," ");//after punctuation put a space
}
}
}
pl[pp]='\0';//setting the last value to null as this is required by the output function
}//complete
int extractintoew(char el[],char ew[],int ep)
{
int i=0;
while(isalpha(el[i]))
{
ew[i]=el[ep];
i++;
ep++;
}
return ep;//ep at this point is one place behind the space or punctuation and returns that number to
}//completed
void convertintopig(char ew[], char pw[])
{
int y,m;
y=wherevowel(ew);//incomplete at this point
if(y==0||y==(-1))//this indicates if it begins with a vowel, or has no vowel at all
{
strcat(ew,"way");
strcpy(pw,ew);
}
else
{
m=strlen(ew);//calculate the length of the string;
memmove(ew,&ew[y],m-y);// m-y indicates that number of alphabets to move
strcat(ew,"ay");
strcpy(pw,ew);//now pw, has the word with the vowels moved back, and truncated with "ay"
}
}//completed
int wherevowel(char ew[])
{
int j;
char *vowel="aeiou";
if(ew[0]=='a'||ew[0]=='e'||ew[0]=='i'||ew[0]=='o'||ew[0]=='u')
{
j=0;
return j;
}
if(ew[0]=='A'||ew[0]=='E'||ew[0]=='I'||ew[0]=='O'||ew[0]=='U')
{
j=0;
return j;
}
else
{
j=strcspn(ew,vowel);
if(j==0)
{
j=(-1);
return j;
}
else return j;//this value here has the place where j occurs
}
}//completed
int copyintopl(char pw[], char pl[], int pp)
{
int a=0;
int b;//declared for strlen of pl
b=strlen(pw);
while(a<b-1)
{
pw[a]=pl[pp];
a++;
pp++;
}
return pp;
}//completed