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
Oooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
mihalych1998 [28]

Answer:

ooooooooo[soooooooo ioooo egg vn

8 0
3 years ago
Task 2
USPshnik [31]
4.
3.
1.
5.
2.
I rearranged them so the program would make sense by arranging the interaction in a logical order then placing input statements in between
6 0
2 years ago
Read 2 more answers
8. This machine is used for high speed, high volume printing l. Can print about 1000 papers at one point in time.
seropon [69]

Answer:

Risographs can produce up to typically 150 pages per minute. So I'm guessing its c.

Explanation:

5 0
3 years ago
need the answer ASAP. I’ll mark brainliest <br><br> they’re all the same options for each sentence.
KengaRu [80]

Answer:

Explanation:

pop(): Remove an item from the end of an array  

push(): Add items to the end of an array  

shift(): Remove an item from the beginning of an array  

unshift(): Add items to the beginning of an array

4 0
3 years ago
What are the two main parts of system unit hardware?
Georgia [21]

Answer: Computers have two main parts: hardware and software

Like piano (hardware) and music (software)

Explanation:

4 0
3 years ago
Other questions:
  • The ________ of the operating system enables users to communicate with the computer system. Select one: A. user interface B. mod
    15·1 answer
  • In ancient times what did kings and tribals chiefs use to communicate
    10·1 answer
  • What are two major techniques involved in green computing
    14·1 answer
  • What is one purpose of an algorithm
    14·1 answer
  • Select the correct answer.
    9·1 answer
  • ¿Es aquel panel que controla la estructura de la tabla dinámica?
    14·2 answers
  • A user finished working on a computer in the lab. What should the user do so
    15·1 answer
  • Complete the sentence with the correct response.
    9·1 answer
  • Write an algorithm to create a customer’s bill for a company. The company sells only five different products. TV, VCR, Remote Co
    13·1 answer
  • Help me please, I'm attempting a test<br>​
    12·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!