This is a question i copy from others,and i write the code but nid u to help figure out problem.
User is required to enter a sentence in English to be transformed to Pig-Latin form. To transform a word to Pig-Latin form, the first letter of the word beginning with a consonant is moved to the back, added with letters ay after the moved consonant. Words that begin with a vowel are simply appended with ay. You can assume the user will not key in any punctuations or uppercase letters.

Example 1:
Please enter a sentence: this is an english sentence
Pig-Latin form: histay isay anay englishay entencesay

Example 2:
Please enter a sentence: hope you have fun
Pig-Latin form: opehay ouyay avehay unfay


My work is

#include <stdio.h>
#include <stdlib.h>
#include<ctype.h>

void initialize(char english[],char piglatin[]);
void readinput(char english[]);
int countwords(char english[]);
void convert(int words,char english[],char piglatin[]);
void writeoutput(char piglatin[]);

main()
{
	char english[80],piglatin[80];
	int words;

	printf("welcome to the Piglatin Generator");
	printf("Type \'End\' when finished\n\n");
	do
	{
		initialize(english,piglatin);
		readinput(english);
		if( toupper(english[0])=='E' &&
			toupper(english[1])=='N'&&
			toupper(english[2])=='D')  break;
		words= countwords(english);
		convert(words,english,piglatin);
		writeoutput(piglatin);
	}
	while(words>=0);
	printf("naveha aa icena ayda");
}

void initialize(char english[],char piglatin[])
{
	int count;
	for(count=0;count<80;++count)
		english[count]= piglatin[count]=' ';
	return;
}

void readinput(char english[])
{
	int count=0;
	char c;
	while((c=getchar())!='\n')
	{
		english[count]=c;
		++count;
	}
	return;
}
int countwords(char english[])
{
	int count,words=1;
	for(count=0;count<79;++count)
		if(english[count]==' '&&english[count+1]!=' ')
			++words;
	return(words);
}
void convert(int words,char english[],char piglatin[])
{
	int n,count;
	int m1=0;
	int m2;
	for(n=1;n<=words;++n)
	{
		count=m1;
		while(english[count]!=' ')
			m2=count++;
		for(count=m1;count<m2;++count)
			piglatin[count+(n-1)]=english[count+1];
		piglatin[m2+(n-1)]= english[m1];
		piglatin[m2+n]= 'a' ;
		
				m1=m2+2;
	}
	
	return;
}

void writeoutput(char piglatin[])
{
	int count=0;
	for(count=0;count<80;++count)
		putchar(piglatin[count]);
	printf("\n");
	return;
}

Now the problem i face in my code is
how to reach the requirement " the first letter of the word beginning with a consonant is moved to the back, added with letters ay after the moved consonant. Words that begin with a vowel are simply appended with ay"?

Recommended Answers

All 16 Replies

Maybe start with reading
- Intro threads
- how to post code threads
- the watermarks at the back of the edit window

All of which tell you about using [code]
[/code] tags when posting code.

insert your properly-indented code between code tags

[ code=c ]
insert code here
[ /code ]


(except, do not have any spaces within tag brackets... i just put those there so it wouldn't actually turn it into "code" ...)

Maybe start with reading
- Intro threads
- how to post code threads
- the watermarks at the back of the edit window

All of which tell you about using [code]
[/code] tags when posting code.

i have attached the .c file .kindly open it and give me a hand on
how to reach the requirement " the first letter of the word beginning with a consonant is moved to the back, added with letters ay after the moved consonant. Words that begin with a vowel are simply appended with ay"?

i'll look at it...

but it sure would be a helluva lot easier on everyone if you were to just post your indented code between the code tags

you'd be a lot more likely to get people to help you if they can just read your code on the webpage without having to go through a lot of contortions.

Thanks for guide.i redo it again
User is required to enter a sentence in English to be transformed to Pig-Latin form. To transform a word to Pig-Latin form, the first letter of the word beginning with a consonant is moved to the back, added with letters ay after the moved consonant. Words that begin with a vowel are simply appended with ay. You can assume the user will not key in any punctuations or uppercase letters.

Example 1:
Please enter a sentence: this is an english sentence
Pig-Latin form: histay isay anay englishay entencesay

Example 2:
Please enter a sentence: hope you have fun
Pig-Latin form: opehay ouyay avehay unfay


My work is
#

include <stdio.h>
#include <stdlib.h>
#include<ctype.h>

void initialize(char english[],char piglatin[]);
void readinput(char english[]);
int countwords(char english[]);
void convert(int words,char english[],char piglatin[]);
void writeoutput(char piglatin[]);

main()
{
char english[80],piglatin[80];
int words;

printf("welcome to the Piglatin Generator");
printf("Type \'End\' when finished\n\n");
do
{
initialize(english,piglatin);
readinput(english);
if( toupper(english[0])=='E' &&
toupper(english[1])=='N'&&
toupper(english[2])=='D') break;
words= countwords(english);
convert(words,english,piglatin);
writeoutput(piglatin);
}
while(words>=0);
printf("naveha aa icena ayda");
}

void initialize(char english[],char piglatin[])
{
int count;
for(count=0;count<80;++count)
english[count]= piglatin[count]=' ';
return;
}

void readinput(char english[])
{
int count=0;
char c;
while((c=getchar())!='\n')
{
english[count]=c;
++count;
}
return;
}
int countwords(char english[])
{
int count,words=1;
for(count=0;count<79;++count)
if(english[count]==' '&&english[count+1]!=' ')
++words;
return(words);
}
void convert(int words,char english[],char piglatin[])
{
int n,count;
int m1=0;
int m2;
for(n=1;n<=words;++n)
{
count=m1;
while(english[count]!=' ')
m2=count++;
for(count=m1;count<m2;++count)
piglatin[count+(n-1)]=english[count+1];
piglatin[m2+(n-1)]= english[m1];
piglatin[m2+n]= 'a' ;

m1=m2+2;
}

return;
}

void writeoutput(char piglatin[])
{
int count=0;
for(count=0;count<80;++count)
putchar(piglatin[count]);
printf("\n");
return;
}

Now the problem i face in my code is
how to reach the requirement " the first letter of the word beginning with a consonant is moved to the back, added with letters ay after the moved consonant. Words that begin with a vowel are simply appended with ay"?

^ nice try. but you should have your opening tag be like this:

and you need to have all your INDENTATIONS (ie, "tabs") copied into the text box.... otherwise it still looks like shiite and we still can't read it.

but anyhow ... i opened your code, read it, and executed it... and im not sure why you're having a problem.

your code essentially works.

-------------------------------------

welcome to the Piglatin GeneratorType 'End' when finished

hello how are you wont you tell me your name

elloha owha reaa ouya ontwa ouya ellta ema ourya amena

------------------------------------

i mean, you're like 99% there. your code is very clear and straightforward.

are you telling me that you've done all this work, wrote all this very nice code and come this far, and [b]now[/b] you're [b]stuck[/b]?

what exactly are you having problems with? what function are you confused on? what are you trying to do that isn't working?[code=c]
and you need to have all your INDENTATIONS (ie, "tabs") copied into the text box.... otherwise it still looks like shiite and we still can't read it.


but anyhow ... i opened your code, read it, and executed it... and im not sure why you're having a problem.

your code essentially works.

-------------------------------------

welcome to the Piglatin GeneratorType 'End' when finished

hello how are you wont you tell me your name

elloha owha reaa ouya ontwa ouya ellta ema ourya amena

------------------------------------

i mean, you're like 99% there. your code is very clear and straightforward.

are you telling me that you've done all this work, wrote all this very nice code and come this far, and now you're stuck?


what exactly are you having problems with? what function are you confused on? what are you trying to do that isn't working?

Perhaps is best if you work in small portions of what you intend to do; testing that you understand the principle first in an isolated state.

e.g.

void readinput(char english[])
{
	int count=0;
	char c;
	while((c=getchar())!='\n')
	{
		english[count]=c;
		++count;
	}
	return;
}

Consider:
The while loop will keep copying characters from stdin until encounters a new line.
What would happen if the newline is not reached before 80 times?

Continue considering:
The while loop has successfully reached a newline before it runs out of space for english.
Still english is not a string, since the '\0' ( string terminator ) hasn't be added to it.

commented: you're so much nicer than everyone else here :-) +1

Thanks for ur help.but the problem now i face is how to reach the requirement "the first letter of the word beginning with a consonant is moved to the back, added with letters ay after the moved consonant. Words that begin with a vowel are simply appended with ay"? just like this two:

Example 1:
Please enter a sentence: this is an english sentence
Pig-Latin form: histay isay anay englishay entencesay

Example 2:
Please enter a sentence: hope you have fun
Pig-Latin form: opehay ouyay avehay unfay

i try to use if else but it cannot work .
kindly share me ur idea

Perhaps is best if you work in small portions of what you intend to do; testing that you understand the principle first in an isolated state.

e.g.

void readinput(char english[])
{
	int count=0;
	char c;
	while((c=getchar())!='\n')
	{
		english[count]=c;
		++count;
	}
	return;
}

Consider:
The while loop will keep copying characters from stdin until encounters a new line.
What would happen if the newline is not reached before 80 times?

Continue considering:
The while loop has successfully reached a newline before it runs out of space for english.
Still english is not a string, since the '\0' ( string terminator ) hasn't be added to it.

thanks for ur question.
i will try to think about it .but now i nid to think how to reach the requirement like the example
Example 1:
Please enter a sentence: this is an english sentence
Pig-Latin form: histay isay anay englishay entencesay

Example 2:
Please enter a sentence: hope you have fun
Pig-Latin form: opehay ouyay avehay unfay

can u share me ur idea? i try to use if else but cannot work.

okay, where did you get the code from?

because I don't believe you wrote it.

okay, where did you get the code from?

because I don't believe you wrote it.

thanks for jephthah's guide.U are right.
honestly,this code i copied from my friend.becos i am really a freshman for C-program.but i really study it . pls trust me .
but my friend stopped doing it as he found that he hardly can reach the requirement the question like the example show.
he is really like C-program but dun want to ask others although i ask him to ask always.
i dun want c him to give up becos i am his only friend.
can u help me again? i try to solve it so i dun nid to post it in the forum .but i am useless.
Can u give me some advice to do it ?

>Can u give me some advice to do it ?
I can give you some advice, but you're not going to like it. My advice is to take a step back and work on simpler things, because you're trying to solve problems and write programs that are too far beyond you right now.

>Can u give me some advice to do it ?
I can give you some advice, but you're not going to like it. My advice is to take a step back and work on simpler things, because you're trying to solve problems and write programs that are too far beyond you right now.

thanks for ur advices.u are right.this one really beyond my standard nw.
i am doing wat u say nw also
as i nid to figure it out also.
but if u can give me some guides, i can solve this question more easily so that i can do more exercise later.
thanks narue for helping me to add code tags
i appreciate it

i concur with narue.

the code you are trying to fix is practically complete.

the change you want to make to it is almost trivial.

the code that you have already, is clear and well-written, and follows a good basic style.

if you can't figure out how to make this change to the code you already have... i can't help you.

i can GIVE you the answer, but that would be counter productive.

Ive already given you a concise answer to the PIG LATIN question in the other thread, yet you cant even plop the function call into a main( ) routine.

i feel like im just giving you rope with which you will wind up hanging yourself.

you need to take a refresher class in basic C programming before attempting these more "advanced" concepts.

i concur with narue.

the code you are trying to fix is practically complete.

the change you want to make to it is almost trivial.

the code that you have already, is clear and well-written, and follows a good basic style.

if you can't figure out how to make this change to the code you already have... i can't help you.

i can GIVE you the answer, but that would be counter productive.

Ive already given you a concise answer to the PIG LATIN question in the other thread, yet you cant even plop the function call into a main( ) routine.

i feel like im just giving you rope with which you will wind up hanging yourself.

you need to take a refresher class in basic C programming before attempting these more "advanced" concepts.

thanks for jephthah,Aia,and Narue.
my friend figure out it alreadi.
i willl follow ur guide to learn it totally again.
the problem i think can close nw.
thanks for ur two-days short course for me .
i learnt a lot from this one.
nw i am taking an engineerin computing class.
it takes about three month.
so i temporarily less time to come here.but i promise once i graduate,i will come here to share u my learning process and my own code.
wish u .

okay.

we'll be looking forward to your return.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.