1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
geniusboy [140]
3 years ago
6

Language: C

Computers and Technology
1 answer:
Vikentia [17]3 years ago
3 0

The .cpp code is avaiable bellow

Code:

#include <stdio.h>

#include <string.h>

int main()

{

    char **kW;

    char *fN;

    int nW = 0;

    kW = malloc(5000 * sizeof(char*));

    for (int i = 0; i<5000; i++)

    {

         kW[i] = (char *)malloc(15);

    }

    fN = (char*)malloc(25);

    int choice;

    while (1)

    {

         printf("1) File text to use as cipher\n");

         printf("2) Make a cipher with the input text file and save result as output file\n");

         printf("3) Decode existing cipher\n");

         printf("4) Exit.\n");

         printf("Enter choice: ");

         scanf("%d", &choice);

         if (choice == 1)

         {

             nW = readFile(kW, fN);

         }

         else if (choice == 2)

         {

             encode(kW, fN, nW);

         }

         else

         {

             Exit();

         }

         printf("\n");

    }

    return 0;

}

int readFile(char** words, char *fN)

{

    FILE *read;

    printf("Enter the name of a cipher text file:");

    scanf("%s", fN);

    read = fopen(fN, "r");

    if (read == NULL)

    {

         puts("Error: Couldn't open file");

         fN = NULL;

         return;

    }

    char line[1000];

    int word = 0;

    while (fgets(line, sizeof line, read) != NULL)

    {

         int i = 0;

         int j = 0;

         while (line[i] != '\0')

         {

             if (line[i] != ' ')

             {

                  if (line[i] >= 65 && line[i] <= 90)

                  {

                       words[word][j] = line[i]; +32;

                  }

                  else

                  {

                       words[word][j] = line[i];

                  }

                  j++;

             }

             else

             {

                  words[word][j] = '\n';

                  j = 0;

                  word++;

             }

             i++;

         }

         words[word][j] = '\n';

         word++;

    }

    return word;

}

void encode(char** words, char *fN, int nwords)

{

    char line[50];

    char result[100];

    if (strcmp(fN, "") == 0)

    {

         nwords = readFile(words, fN);

    }

    getchar();

    printf("Enter a secret message(and press enter): ");

    gets(line);    

    int i = 0, j = 0;

    int w = 0, k = 0;

    while (line[i] != '\0')

    {        

         if (line[i] >= 65 && line[i] <= 90)

         {

             line[i] = line[i] + 32;

         }

         w = 0;

         int found = 0;

         while (w<nwords)

         {

             j = 0;

             while (words[w][j] != '\0')

             {

                  if (line[i] == words[w][j])

                  {

                       printf("%c -> %d,%d \n", line[i], w, j);

                       found = 1;

                       break;

                  }

                  j++;

             }

             if (found == 1)

                  break;

             w++;

         }

         i++;

    }

    result[k] = '\n';

}

void Exit()

{

    exit(0);

}

You might be interested in
ICT excel data homework
kifflom [539]
Static data field - the field is set at the start of the program (if creating a program) and can not be changed, its value will be constant. 
<span>Instance data field - can be manipulated by the user, so that its value can be stored: for example you have a data field storing how many hours a person can work in one day, the field will be static as there are always 24h in a day and that can not change. </span>
<span>If you have a second data field storing how many hours a certain employee worked that field will be an instance data field as its values can differ.</span>
4 0
3 years ago
Which of the following is the process of writing the step-by-step instructions that can be understood by a computer?
Aleks04 [339]

Answer:

computer programming

Explanation:

says the answer in the question

5 0
3 years ago
Write at least complete set of HTML code to hyperlink to “Home.html”..
faltersainse [42]

Answer:

HTML Link Colors

By default, a link will appear like this (in all browsers):

An unvisited link is underlined and blue

A visited link is underlined and purple

An active link is underlined and red

You can change the link state colors, by using CSS:

8 0
3 years ago
By default, which of these traffic source dimensions does google analytics capture for each user that visits your website?
natta225 [31]

The question above has multiple choices as listed;

<span />a. Source and Medium<span>
</span>

<span>b. Campaign and Ad Content</span>
<span />

<span>c. Campaign and Medium
</span><span>
</span><span>d. Source, Medium, Campaign, and Ad Content
</span>
<span />

<span>The correct answer is A. Source and Medium</span>

Source and medium combines the dimensions source and medium. Anyone referred to a website has an origin or a source. Examples of possible sources include Google, Facebook.com, and direct for those who typed your URL directly. Every referral, on the other hand, has a medium and possible examples of medium include organic, cost per click, referral, email, and none.






5 0
3 years ago
A person clicks on an ad of a fitness club in a blog on nutrition. The person conducts a search on yoga and moves to another web
Sloan [31]

Answer: the answer is B.

hope this help

3 0
3 years ago
Other questions:
  • Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with a
    13·1 answer
  • strategy that is used to help improve the chances that your site will be found by search engines is known as search engine
    12·1 answer
  • You open the home page for www.alpineskihouse. On the home page, you see a link for the weather report. You want to view the wea
    6·1 answer
  • Write a program in c++ that asks the user for a sequence of n​integers, where the user provides the number of elements n​ then e
    12·1 answer
  • If a function doesn’t return a value, the word _________ will appear as its return type.
    6·1 answer
  • What is first page of website called​
    10·1 answer
  • What is the next line?
    7·1 answer
  • Please help with coding assignment.
    11·1 answer
  • In two to three sentences, define "home row" and explain why it is important.
    6·2 answers
  • Hey there! What would be the best way for me to learn Lua script? As well as learn Data Store, and other stuff. Thanks! Brainly
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!