I want to go through a sentence and convert each word in it to pig latin, while also preserving the punctuation. Here is the code I'm using:

```
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(void){
  char input[100];
  int arraypos=0;
  int ch;
  char word[100];

  char output[200]={'\0'};
  while ((ch=getchar())!='\n'){
          input[arraypos]=ch;
      arraypos++;
    }
    input[arraypos]='\0';

    int j=0;
    int index=0;
    char punct[1];
   while (input[j]!='\0'){
      while(!(isspace(input[j]))&&(!(ispunct(input[j])))){
    word[index]=input[j];
    index++;
    j++;
      }
      word[index]='\0';
      strcat(output, piglatin(word));
      punct[0]=input[j];
      punct[1]='\0';
      strcat(output,punct);
      index=0;
      j++;
   } 

     printf("%s\n", output);
}

```

I am sure that the piglatin function used here works . The problem is with looping through this sentence and working with it.

If I remove the first while loop:

```
while (input[j]!='\0'){

```

then if the I enter: `Hello,my name is Michael` the output is `Ellohay,` ( which is correct).
However, if I add the same while loop to make it work for each word. It gives me a segmentation fault.