I made a program in C for my school work but i cant make it work.Piglatin means cutting the first character of a word and adding it to the end and finally adding an "a" to the end.For example teacher -> eacherta. Can you help me finding the problem?
/***************************************************************************************/
/********************************CTP 102 Elementary Data Structures*********************/
/********************************Büke Yolaçan*******************************************/
/********************************English to piglatin converter**************************/
/***************************************************************************************/
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<stdlib.h>
#define MAX 80
void call()
{
char str[80];
char english[80];
int length,
a=0,
b=0;
printf("Please enter a word to be converted to piglatin: ");
fgets(str,MAX,stdin); /*store sentence in str*/
length = strlen(str);
printf("\nThis is your english to piglatin converted word: ");
while(0<=length)
{
english[0]=str[0]; /*copy str to english*/
if(english[0]==' '||english[0]=='\0') /*check for whitespace*/
{
english[0]='\0';
b=0;
printf(" %s",letter(english));
a++;
}
}
int main()
{
char * letter(char *str)
{
static char temp[MAX];
strcpy(temp,++str); //copy word starting from second character to temp
temp[strlen(temp)]=*(--str); //copy the first char of word to end of temp
temp[strlen(temp)+1]= '\0'; // Null terminate temp
strcat(temp,"a"); // append "a to the string.
return temp;
}
call(); /*call function to read in sentence & print piglatin*/
return(0);
}