Question
Please use macOS or Linux to write a simple C shell that can translate: Translator> trans_SE tigre tiger Translator> trans_EF mouse souris Translator> exit You
Please use macOS or Linux to write a simple C shell that can translate:
Translator> trans_SE tigre tiger
Translator> trans_EF mouse souris
Translator> exit
You only need to write a C shell, no need to write translator code because I will give the translator code below:
#include #include
#define LENGTH 30 #define TOTAL 8
//globlal destination char ES[TOTAL][LENGTH]={"gato", "perro", "pajaro", "raton", "vaca", "tigre", "caballo", "mono" };
char EF[TOTAL][LENGTH]={"chat", "chien", "oiseau", "souris", "vache", "tigre", "cheval", "singe" };
char *english[TOTAL]={"cat", "dog", "bird", "mouse", "cow", "tiger", "horse", "monkey"};
//api for translates the word void trans_ES(char *wordsrc, char *worddst, char *word) { int i =0,index=0; int flag=0; if(!strcmp(wordsrc, "english") && !strcmp(worddst, "spanish")) { for(i=0; i { if(!strcmp(word, english[i])) { flag=1; index=i; break; } } if(!flag) { printf("word: %s not found in dictionary ", word ); } else { printf("%s is an English word that translates as %s in Spanish ", word, ES[index]); } } }
void trans_EF(char *wordsrc, char *worddst, char *word) { int i =0,index=0; int flag=0; if(!strcmp(wordsrc, "english") && !strcmp(worddst, "french")) { for(i=0; i { if(!strcmp(word, english[i])) { flag=1; index=i; break; } } if(!flag) { printf("word: %s not found in dictionary ", word ); } else { printf("%s is an English word that translates as %s in French ", word, EF[index]); } } }
void trans_SE(char *wordsrc, char *worddst, char *word) { int i =0,index=0; int flag=0; if(!strcmp(wordsrc, "spanish") && !strcmp(worddst, "english")) { for(i=0; i { if(!strcmp(word, ES[i])) { flag=1; index=i; break; } } if(!flag) { printf("word: %s not found in dictionary ", word ); } else { printf("%s is an Spanish word that translates as %s in English ", word, english[index]); } } }
void trans_SF(char *wordsrc, char *worddst, char *word) { int i =0,index=0; int flag=0; if(!strcmp(wordsrc, "spanish") && !strcmp(worddst, "french")) { for(i=0; i { if(!strcmp(word, ES[i])) { flag=1; index=i; break; } } if(!flag) { printf("word: %s not found in dictionary ", word ); } else { printf("%s is an Spanish word that translates as %s in French ", word, EF[index]); } } }
void trans_FE(char *wordsrc, char *worddst, char *word) { int i =0,index=0; int flag=0; if(!strcmp(wordsrc, "french") && !strcmp(worddst, "english")) { for(i=0; i { if(!strcmp(word, EF[i])) { flag=1; index=i; break; } } if(!flag) { printf("word: %s not found in dictionary ", word ); } else { printf("%s is an French word that translates as %s in English ", word, english[index]); } } }
void trans_FS(char *wordsrc, char *worddst, char *word) { int i =0,index=0; int flag=0; if(!strcmp(wordsrc, "french") && !strcmp(worddst, "spanish")) { for(i=0; i { if(!strcmp(word, EF[i])) { flag=1; index=i; break; } } if(!flag) { printf("word: %s not found in dictionary ", word ); } else { printf("%s is an French word that translates as %s in English ", word, ES[index]); } } } int main() { char c ; char ch; char buf[10]; char *test="N"; char word[LENGTH], wordsrc[LENGTH],worddst[LENGTH]; int i =0; int flag1 =0,start=0; memset(buf, '\0', sizeof(buf)); while (strcmp(buf, test)) { memset(buf, '\0', sizeof(buf)); memset(word, '\0', sizeof(word)); memset(wordsrc, '\0', sizeof(wordsrc)); memset(worddst, '\0', sizeof(worddst)); printf("Please enter a word to translate: "); scanf("%s", word); /*if(i=0; i { int flag=0; if(!strcmp(word, english[i])) { flag=1; break; } if(!flag) { printf("word: %s not found in dictionary ", word ); } } */ do { printf("Please enter the source language: "); scanf("%s", wordsrc); printf("Please enter the destination language: "); scanf("%s", worddst); if((!strcmp(wordsrc, "english") || !strcmp(wordsrc, "spanish") ||!strcmp(worddst, "french")) && (!strcmp(worddst, "french") ||!strcmp(worddst, "english") || !strcmp(worddst, "spanish"))) { flag1=1; } else { printf("In correct sorce/destination language.. Please enter correct language.. "); } }while(!flag1); while(ch=getchar() != ' '); trans_ES(wordsrc, worddst, word); trans_EF(wordsrc, worddst, word); trans_SE(wordsrc, worddst, word); trans_SF(wordsrc, worddst, word); trans_FE(wordsrc, worddst, word); trans_FS(wordsrc, worddst, word); printf("Do you want to translate a new word? (Y/N):"); scanf("%[^ ]s",buf); //printf("continue-%s %s %d ",buf, test, strcmp(buf, test)); } return 0; }
The shell issues its prompt: Translator> and waits for a command. When a command is issued in the shell, the shell executes the procedure associated with the command. Your shell is a very simple one that can take 5 commands: trans_ES, trans_SE, trans_EF, trans_FE, exit. When the function terminates, the process terminates too. Upon receiving the exit signal, the shell process breaks out of its waiting loop and reads the new command. You will need to use the following system calls: fork(), wait(), exec() (or another function from the exec() family), exit().
English Cat Dog Bird Mouse Cow | Tiger Horse Monkey Spanish Gato Perro Pajaro Raton | Vaca Tigre Caballo Mono English Cat Dog Bird | Mouse Cow | Tiger Horse Monkey French Chat Chien Oiseau | Souris Vache Tigre Cheval Singe English Cat Dog Bird Mouse Cow | Tiger Horse Monkey Spanish Gato Perro Pajaro Raton | Vaca Tigre Caballo Mono English Cat Dog Bird | Mouse Cow | Tiger Horse Monkey French Chat Chien Oiseau | Souris Vache Tigre Cheval SingeStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started