Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can anyone show me how to write this code? e purpose characlers and ot eris shor

ID: 3762213 • Letter: C

Question



can anyone show me how to write this code?

e purpose characlers and ot eris short assignment is to ghe you some practice usin nd Strings. You wil create a program by shifting each cnvaracter's tw shfting each letter some number of pluaces Thus, i he sht s2 ssape C. B becomes D, and so on. Like this thel ABCDEFGH z you can do this by simply doing arithmeic with characters, but you C that he result is a chracter using a cast. If, tor should reassure C that the eter contains the value cu can turn back into a character by saying (char value ample, alue,then R ck into a character by saying i cha: I 1 letter gives e irregr result e7, which + 2 . geng me 2" 2 : does not gre you the letter + Unfortunately, itar) t tom the picture above). But if you reakze you wem past '2, you can ' n, tyou can see why tromm subract 26 (so the result is 2 224), and tris wll give This also means that if you encode a message with a shit af n, you can decode Ths a t with ancther shit of 26 n Your program should first call a funcion processPile, which reads a nessage from a fie (eongress.txt) into a very large character array The unchon should convert all af the letters into uppercase characters. You may iscard ail the punctuation marks, dgts, blaniks, and anyhing else from the input string Your program should then accept the amount to shit as an input to a function The input parameter shouid be 13, although for your sesting Your function should purposes, you can simplity things by using a shift of 1. Your function ach letter by shiting & the correct amount, and put the encoded letters into null-terminated array of characters Finaly, you should create a function, outputCode I1,which outputs the final encoded message in blocks of five letters, ten blocks per ine. The last ine may be shorter than five blocks, and the last block may be shorter than five letters

Explanation / Answer

Complete Program:

// File: Cipher.c

#include <stdio.h>
#include <stdlib.h>

#define MAX 500

void processFile(int *text);
void cipher(int *text, int *code);
void outputCode(int *code);

int main()
{
    int text[MAX];
int code[MAX];
  
    processFile(text);
    cipher(text, code);
    outputCode(code);
   
printf(" ");
    return 0;
}


void processFile(int *text)
{
FILE *infile = fopen("congress.txt", "r");

    int i;
    char letter = 0;   
   
    for(i = 0; !feof(infile) && i < MAX - 1; )
{
        fscanf(infile, "%c", &letter);

        if(letter <= 'Z' && letter >= 'A')
  {
            text[i] = letter;
            i++;
        }

        if(letter <= 'z' && letter >= 'a')
  {
            text[i] = letter - 32;
            i++;
        }
    }

    text[i]='';
}


void cipher(int *text, int *code)
{
    int i;

    for(i = 0; text[i] != 0; i++)
{
  char letter = text[i];

        if(letter <= 'Y' && letter >= 'A')
  {
            code[i] = (char)(letter + 1);      
        }

        if(letter == 'Z')
  {
            code[i] = (char)(letter - 25);
        }
    }

    for(; i < MAX; i++)
  code[i] = 0;
}

void outputCode(int *code)
{
  FILE *outfile = fopen("csis.txt", "w");
    
    for(int i = 0; code[i] != 0; i++)
{
        if(i != 0 && i % 50 == 0)
  {
            printf(" ");
            fprintf(outfile, " ");
        }
  else if(i != 0 && i % 5 == 0)
  {
            printf(" ");
            fprintf(outfile, " ");
        }

        printf("%c", code[i]);
        fprintf(outfile, "%c", code[i]);
    }

fclose(outfile);
}


Input file: congress.txt


Output file: csis.txt

Output on screen:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote