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);

}

Recommended Answers

All 4 Replies

I'd start with the fact that functions can't be nested inside of each other in C. You're also calling letter before it's declared.

Start by reading this and this.

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,n,d,l,k,z,j;
char a[100];
k=0;
d=0;
clrscr();
puts("enter the line");
gets(a);
l=strlen(a);
for(i=0;i<=l;i++)
{
if(a[i]==' '||a[i]=='\0')
{
k++;
n=i-d;
d=d+(n+1);
z=0;
if(z==0)
{
for(j=(i-n)+1;j<i;j++)
{
printf("%c",a[j]);
}
if(n!=0)
{
printf("%c",a[i-n]);
printf("a ");
}
}
}
}
getch();
}

/*if satisfy with this program send me mail at <snipped email> */

chalasesha, you obviously need to read my links, too. As well as this.

And why would someone be satisfied with a program you wrote? What could they possibly learn by handing in your work?Especially poor and non standard code.

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.