Question

C Code! dictionary.c, start by downloading the boilerplate1 code from Blackboard. Read the code, then complete...

C Code! dictionary.c, start by downloading the boilerplate1 code from Blackboard.

Read the code, then complete it at all places indicated by TODO.

For this second assignment, you do not receive precise specifications. This is on purpose: in the software industry, you’ll find a lot of cases when you need to finish code started by others, while not being given precise instructions on how the code works or is supposed to work. The comments in the code will help you, but you will have to do some detective work with some examples for which you run the code “by hand” in your mind to complete the code.

For this dictionary.c program, you should end up with a simple English-French and French-English dictionary with a couple of about 350 words. There are smart ways and less smart ways to look up a word in a sorted array. For this assignment, these different algorithmic ways do not matter. You simply need to find a way to identify at which index i a certain word appears in an array of words and print out the corresponding French word, at the same index i.

You may use the strcmp function available when including string.h.

Here are a couple of example runs of the complete program:

English-French Dictionary Enter e for English-French Enter f for French-English e

Please enter a word in English: time The English word "time" corresponds to the French word "temps".

Here's the code! you don't need to enter in all of the french and english words, just figure out the program that searches for the words and what they correspond to--main code at the bottom

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

const int NUMBER_ENTRIES = 352;

const char* english[NUMBER_ENTRIES] = {"war",
                                       "size",
                       "her",
                                       "song"
};

const char* french[NUMBER_ENTRIES] = { "guerre",
                                       "taille",
                                       "sa",
                                       "chanson"
};


int main(int argc, char **argv) {
  const int BUFFER_LENGTH = 128;
  char c, t;
  char user_word[BUFFER_LENGTH];
  enum { ENGLISH_FRENCH, FRENCH_ENGLISH } direction;
  int i;
  /* TODO: Add additional declarations here */

  printf("English-French Dictionary\n\n");
  do {
    printf("Enter e for English-French\n");
    printf("Enter f for French-English\n");
    scanf("%c", &c);
    scanf("%c", &t);
  } while (!((c == 'e') || (c == 'f')));

  switch (c) {
  case 'e':
    direction = ENGLISH_FRENCH;
    break;
  case 'f':
    direction = FRENCH_ENGLISH;
    break;
  }

  printf("Please enter a word in ");
  switch (direction) {
  case ENGLISH_FRENCH:
    printf("English");
    break;
  case FRENCH_ENGLISH:
    printf("French");
    break;
  }
  printf(": ");
  i = 0;
  scanf("%c", &c);
  while (c != '\n') {
    user_word[i] = c;
    i++;
    if (i >= BUFFER_LENGTH) {
      i = BUFFER_LENGTH-1;
    }
    scanf("%c", &c);
  }
  user_word[i] = '\0';

  switch (direction) {
  case ENGLISH_FRENCH:
    /* TODO */
    break;
  case FRENCH_ENGLISH:
    /* TODO */
    break;
  }

  return 0;
}

Homework Answers

Answer #1

C program to find corresponding words in English-French and verse versa.

Source Code

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

const int NUMBER_ENTRIES = 352;

const char* english_NUMBER_ENTRIES[5]= {"war","size", "her","song","time"};

const char* french_NUMBER_ENTRIES[5] = {"guerre","taille","sa", "chanson","temp"};


int main(int argc, char **argv) 
{
  const int BUFFER_LENGTH = 128;
  char c, t;
  char user_word[BUFFER_LENGTH];
  enum { ENGLISH_FRENCH, FRENCH_ENGLISH } direction;
  int i;
  /* TODO: Add additional declarations here */
           printf("Dictionary\n\n");
  printf("English-French Dictionary\n\n");
  do {
    printf("Enter e for English-French\n");
    printf("Enter f for French-English\n");
    scanf("%c", &c);
    scanf("%c", &t);
  } while (!((c == 'e') || (c == 'f')));

  switch (c) {
  case 'e':
    direction = ENGLISH_FRENCH;
    break;
  case 'f':
    direction = FRENCH_ENGLISH;
    break;
  }

  printf("Please enter a word in ");
  switch (direction) {
  case ENGLISH_FRENCH:
    printf("English");
    break;
  case FRENCH_ENGLISH:
    printf("French");
    break;
  }
  printf(": ");
  i = 0;
  scanf("%c", &c);
  while (c != '\n') {
    user_word[i] = c;
    i++;
    if (i >= BUFFER_LENGTH) {
      i = BUFFER_LENGTH-1;
    }
    scanf("%c", &c);
  }
  user_word[i] = '\0';

  switch (direction) {
  case ENGLISH_FRENCH:
   printf(" The corresponding word is: ");
    /* TODO */
    break;
  case FRENCH_ENGLISH:
  printf(" The corresponding word is: ");
    /* TODO */
    break;
  }

  return 0;
}

The Output

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
C CODE PLZ! Need all TO DO sections finished thanks #include <stdio.h> int main(int argc, char...
C CODE PLZ! Need all TO DO sections finished thanks #include <stdio.h> int main(int argc, char **argv) { const int BUF_LEN = 128; char str[BUF_LEN]; int i; char c; int is_binary; int d, n; /* Get the user to enter a string */ printf("Please enter a string made of 0s and 1s, finishing the entry by pressing Enter.\n"); for (i=0; i<BUF_LEN-1; i++) { scanf("%c", &c); if (c == '\n') { break; } str[i] = c; } str[i] = '\0'; /*...
The code is in C programming language pls convert it into python. Thanks. Program --> #include...
The code is in C programming language pls convert it into python. Thanks. Program --> #include <stdio.h> #include <stdlib.h> void main() { //declare variables FILE *fileptr; char filename[15]; char charRead; char filedata[200],searchString[50]; int i=0,j=0,countNoOfWord=0,count=0; //enter the filename to be opened printf("Enter the filename to be opened \n"); scanf("%s", filename); /* open the file for reading */ fileptr = fopen(filename, "r"); //check file exit if (fileptr == NULL) { printf("Cannot open file \n"); exit(0); } charRead = fgetc(fileptr); //read the string...
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main()...
Construct a flowchart based on this code and write its equivalent algorithms. #include <stdio.h> int main() { int x,y; float result; char ch; //to store operator choice printf("Enter first number: "); scanf("%d",&x); printf("Enter second number: "); scanf("%d",&y); printf("Choose operation to perform (+,-,*,/): "); scanf(" %c",&ch); result=0; switch(ch) { case '+': result=x+y; break; case '-': result=x-y; break; case '*': result=x*y; break; case '/': result=(float)x/(float)y; break; case '%': result=x%y; break; default: printf("Invalid operation.\n"); } printf("Result: %d %c %d = %.2f\n",x,ch,y,result); // Directly...
I'm trying to find a code to check the occurrences of the word or string I...
I'm trying to find a code to check the occurrences of the word or string I wrote my own code but it's not working can you please help and fix my code #include <stdio.h> #include <string.h> #define MAX_SIZE 100 // Maximum string size int main() { char str[MAX_SIZE]; char tosearch[MAX_SIZE]; printf("Enter any string: "); gets(str); printf("Enter word to search occurrences: "); gets(tosearch); int cursor = 0; int i = 0; int stringLen = 0; int searchLen = 0; int count1;...
I am trying to write a program in C language but keep running into errors. Any...
I am trying to write a program in C language but keep running into errors. Any help would be awesome. here is my code I have so far. #include <stdio.h> #include <conio.h> #include <string.h> int main(){    int lenght, i = 0, state = 0;    char line[100];    printf("enter the string for checking of comment line: \n");    gets(line);    while(i < strline(line)){        switch(state){            case 0: if (line[i] == '/'){               ...
I've just finished typing my code in C, but I don't know how to draw a...
I've just finished typing my code in C, but I don't know how to draw a flowchart. Can somebody help me create a flow chart of this C program please? #include <stdio.h> int main(void){ char answer; // user's inputted single character int score = 0; // initialize score to 0 printf("-----------------------------------\n"); printf("\tMood Self Assessment\n"); printf("-----------------------------------\n"); printf("This Mood Self-Assessment program can help you determine and understand how\nyou are feeling recently."); printf("The user has to answer 3 questions honestly and\ntruthfully in order...
"C language" Take this code and make the minor modification necessary to create a circular linked...
"C language" Take this code and make the minor modification necessary to create a circular linked list (Hint: Store a pointer to the first node in the next pointer of the last node.) Demonstrate that this is working by traversing the list until the first pointer is encountered 3 times. Next redefine the node structure to include a back pointer. This will enable your program to move from front to back and then from back to front. It is not...
Run Using Kali Linux....Create a source code file named "Lab1.c". The code is as follows. A...
Run Using Kali Linux....Create a source code file named "Lab1.c". The code is as follows. A child is created and prints a message five times. The original process (parent) prints a message only three times. How would this code look on the compiler if you could please post the code and the compiler results. Need Reference Thank You #include <sys/types.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> int main() { pid_t pid; char *message; int n; printf("fork program starting\n"); pid =...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8...
Error compiler. need fix code for febonacci Iterative like 0 1 1 2 3 5 8 13 21 34 55 ....... and also need add code complexity time if you want! here code.c --------------------------------------------------------------------------------------------------------------------- #include <stdio.h> #include <math.h> int fibonacciIterative( int n ) { int fib[ n + 1 ]; int i; fib[ 0 ] = 0; fib[ 1 ] = 1; for ( i = 2; i < n; i++ ) { fib[ i ] = fib[ i -...
create case 4 #include <stdio.h> int main(void) { int counter; int choice; FILE *fp; char item[100];...
create case 4 #include <stdio.h> int main(void) { int counter; int choice; FILE *fp; char item[100]; while(1) { printf("Welcome to my shopping list\n\n"); printf("Main Menu:\n"); printf("1. Add to list\n"); printf("2. Print List\n"); printf("3. Delete List\n"); printf("4. Remove an item from the List\n"); printf("5. Exit\n\n"); scanf("%i", &choice); switch(choice) { case 1: //add to list //get the input from the user printf("Enter item: "); scanf("%s", item); //open the file fp = fopen("list.txt","a"); //write to the file fprintf(fp, "\n%s", item); //close the file...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT