Question

In: Computer Science

Using a text editor, create a file english.txt containing the following words: yes no go come...

Using a text editor, create a file english.txt containing the following 
    words:
    
    yes no go come thanks goodbye
    
    Create a second file chinese.txt contain the following words:
    
    shi bu qu lai xiexie zaijian
    
    Write a program that reads the words from english.txt so that
    the successive slots of a char * array english point to them. 
    Use the %s conversion code in a fscanf call to read one word
    at a time.
             
    Similarly, read the words from chinese.txt so that the 
    successive slots of a char * array chinese point to them.
    
    Your program should then execute a loop that prompts the user 
    for an English word, reads it in (use scanf), and then 
    displays the corresponding Chinese word. The loop should 
    continue until the user enters the word "done". 

Solutions

Expert Solution

If you have any doubts, please give me comment...

#include<stdio.h>

#include<string.h>

#define MAX_SIZE 100

int main(){

    char english_words[MAX_SIZE][50], chinese_words[MAX_SIZE][50];

    char word[50];

    int n, i, j;

    FILE *eng_fp, *chinese_fp;

    eng_fp = fopen("english.txt", "r");

    if(!eng_fp){

        printf("Unable to open english.txt\n");

        return -1;

    }

    chinese_fp = fopen("chinese.txt", "r");

    if(!chinese_fp){

        printf("Unable to open chinese.txt\n");

        return -1;

    }

    n = 0;

    while(!feof(eng_fp)){

        fscanf(eng_fp, "%s", english_words[n]);

        n++;

    }

    n = 0;

    while(!feof(chinese_fp)){

        fscanf(chinese_fp, "%s", chinese_words[n]);

        n++;

    }

    fclose(chinese_fp);

    fclose(eng_fp);

    printf("Enter english word (enter 'done' to terminate): ");

    scanf("%s", word);

    while(strcmp(word, "done")!=0){

        int found = 0;

        for(i=0; i<n; i++){

            if(strcmp(english_words[i], word)==0){

                found=1;

                break;

            }

        }

        if(found){

            printf("%s corresponding chinese word is: %s\n", word, chinese_words[i]);

        }

        else{

            printf("English word %s not found!\n", word);

        }

        printf("\nEnter english word (enter 'done' to terminate): ");

        scanf("%s", word);

    }

    return 0;

}


Related Solutions

In linux , Using a simple text editor, create a text file with the following name...
In linux , Using a simple text editor, create a text file with the following name &quot;Test&quot; and content: GNU GENERAL PUBLIC LICENSE The GNU General Public License is a free, copy left license for the GNU General Public License is intended to guarantee your freedom to GNU General Public License for most of our software; it applies … 2-Write the command to create the text file. 3-Print the file permissions. 4-Create a directory named &quot;361&quot; 5-Copy file &quot;Test&quot; to...
Word Frequencies (Concordance)    1. Use a text editor to create a text file (ex: myPaper.txt)...
Word Frequencies (Concordance)    1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE: (write your program so that...
Use Vi text editor or ATOM to create a bash script file. Use the file name...
Use Vi text editor or ATOM to create a bash script file. Use the file name ayaan.sh. The script when ran it will execute the following commands all at once as script. Test your script file make sure it works. Here is the list of actions the script will do: It will create the following directory structure data2/new2/mondaynews off your home directory. inside the mondaynews, create 4 files sports.txt, baseball.txt, file1.txt and file2.txt. Make sure file1.txt and file2.txt are hidden...
Python: Word Frequencies (Concordance) 1. Use a text editor to create a text file (ex: myPaper.txt)...
Python: Word Frequencies (Concordance) 1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE: (write your program so that...
a) Using vi (or from your favorite editor) create a file called myscript. Enter the following...
a) Using vi (or from your favorite editor) create a file called myscript. Enter the following text into the myscript file. #!/bin/bash echo -e "this is a sample shell script. \t It displays mounted filesystems \a" mount b) Now, save the file and quit the editor. c) type ls -l myscript and hit enter. What permissions do you have on the file? d) type bash myscript and hit enter. What did it do? e) what does the \t and \a...
Go to your “Documents” directory; a) Create a file “file1” with the text “hello” in it;...
Go to your “Documents” directory; a) Create a file “file1” with the text “hello” in it; Provide command and screenshot. b) Create a hard link named “file2” linked to “file1”; c) Create a soft link named “soft1” linked to “file1”; create another soft link named “soft2” linked to “file2”. d) View information of the 4 files (what command should you use to produce output) – how do you verify which file is a hard link and which file is a...
Python File program 5: Word Frequencies (Concordance)    20 pts 1. Use a text editor to create...
Python File program 5: Word Frequencies (Concordance)    20 pts 1. Use a text editor to create a text file (ex: myPaper.txt) It should contain at least 2 paragraphs with around 200 or more words. 2. Write a Python program (HW19.py) that asks the user to provide the name of the text file. Be SURE to check that it exists! Do NOT hard-code the name of the file! Use the entry provided by the user! read from the text file NOTE:...
1. Create a local file on your hard drive by using the NotePad editor that comes...
1. Create a local file on your hard drive by using the NotePad editor that comes with Windows or TextEdit on the MAC. Type into this file some remarks stating that you understand the FTP process. 2. Save it with the name "assign3.txt" 3. Start the FTP program. (SSH for Windows OR FileZilla for MAC) 4. Log on to electron.cs.uwindsor.ca server how do i do this on a mac computer It is intro to internet class
Write a C++ program to create a text file. Your file should contain the following text:...
Write a C++ program to create a text file. Your file should contain the following text: Batch files are text files created by programmer. The file is written in notepad. Creating a text file and writing to it by using fstream: to write to a file, you need to open thew file as write mode. To do so, include a header filr to your program. Create an object of type fsrteam. Open the file as write mode. Reading from a...
Download the AddValueNewArray.java file, and open it in jGrasp (or a text editor of your choice)....
Download the AddValueNewArray.java file, and open it in jGrasp (or a text editor of your choice). This program behaves similarly to the AddValueToArray program from before. However, instead of modifying the array in-place, it will return a new array holding the modification. The original array does not change. For simplicity, the array used is “hard-coded” in main, though the method you write should work with any array. Example output with the command-line argument 3 is shown below: Original array: 3...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT