Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi all, this C program runs correctly, however, I need the program to know to te

ID: 3624650 • Letter: H

Question

Hi all, this C program runs correctly, however, I need the program to know to terminate when a period "." is typed at the end of the sentence.
Currently, my program translates "Cat." as "at.cay" When I really want it translated as "atcay."

Any solutions to this problem!? (I'm working in linux by the way)

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

void printLatinWord(char *a);
int main(void)
{
char phrase[70]; //maximum of 70 characters
char *token; //pointer used
printf("Enter the phrase to translate: ");
fgets(phrase, 70, stdin);
token = strtok(phrase, " ");
printf(" The translated sentence is: ");
while (token != NULL)
{
char phrase[70];
strcpy(phrase, token);
printLatinWord(phrase);
token = strtok(NULL, " ");
}
token = strtok(phrase, " ");
printf(" ");
return 0;
}
void printLatinWord(char *a)
{
while (strchr("aeiouAEIOU",*a) == NULL)
{
char c=*a;
char *t=a, *f=a+1;
while (*f) *t++=*f++;
*t=c;
}
printf("%say ", a);
return;
}

Explanation / Answer

upon entering the printLatinWord funtion, check to see if the last character of the phrase is a period. If it is, remove it and then before returning print the period back out.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote