I have breakdown the problem into several step of mine to translate into pig latin
1.Loop Locate the space in the array
- if now(arr) is not space and not null then keep searching(+1 arr)
- if null then break (mean that go to next step 2)
2.start copying the value to pig latin variable
-store start to temp
-start copying value from start until locatespace-2 to pig_latin
-add temp to pig_latin[index]
-add char 'a' and 'y' and to piglatin[index+1] and piglatin[locatespace+2]
-add space to piglatin[index+3]
3.Start is locatespace+1(which is after space)
//end of my algorithm
So, I've Updated my program and succesfully do this with my own...this is the last problem, and it's related to null
void pigLatin(char english[])
{
int locateSpace = 0;
int index = 0;
int start = 0;
int i = 0;
char piglatin[80];
for (; english[i] != '\0'; i++, locateSpace++)
{
char temp = english[i];
for (; english[i] != ' ' && english[i] != '\0'; i++) {
locateSpace++;
}
for (; start < locateSpace - 1 ; start++ , index++) {
piglatin[index] = english[start +1];
}
piglatin[index] = temp;
piglatin[index+1] = 'a';
piglatin[index+2] = 'y';
piglatin[index + 3] = ' ';
index += 4;
start = locateSpace + 1;
}
piglatin[index] = '\0';
printf("\n%s", piglatin);
}
So, my problem is
- How to insert null to end piglatin variable with?it seems like i don't have idea with this
I've trying a lot of ways but still cant figure it out, so any idea?