#include <stdio.h>
#include <string.h>
int main() {
char input[1000];
// Step 1: Get user input
printf("Enter a sentence: ");
fgets(input, sizeof(input), stdin);
// Step 2: Open a pipe to Google Translate
FILE *pipe = popen("trans -b :en", "w");
// Step 3: Check if the pipe is successfully opened
if (pipe == NULL) {
perror("Error opening pipe to Google Translate");
return 1;
}
// Step 4: Remove the newline character from the input
size_t len = strlen(input);
if (input[len - 1] == '\n') {
input[len - 1] = '\0';
}
// Step 5: Send the user input to Google Translate
fprintf(pipe, "%s", input);
fflush(pipe);
// Step 6: Read and print the translated output
printf("Translated sentence: ");
char output[1000];
while (fgets(output, sizeof(output), pipe) != NULL) {
printf("%s", output);
}
// Step 7: Close the pipe
pclose(pipe);
return 0;
}