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

THIS MUST BE RUNNING IN C ENVIRONMENT The purpose of this exercise is to introdu

ID: 3614188 • Letter: T

Question

THIS MUST BE RUNNING IN C ENVIRONMENT
The purpose of this exercise is to introduce the file i/o in C.Make a simple program that reads in an input file named"Code.txt", reads words from that file (until EOF, end of file),and then "decodes" the message hidden in the input by saving everyfifth word into a 2-dimensional character array (array ofcstrings). As you read words from the file, print them to thescreen as a paragraph (rather than one word per line, as found inthe file). When all code words have been saved, print the decodedmessage to the screen with an appropriate explanation (e.g. "Yourdecoded message says: ...." Finally, write the newlydecoded message to an output file called "Message.txt."

The file "Code.txt" is available to you
One
perspective
is
that
English
language
is
not
really
Literature
There
are
not
even
180
types
of
language.
This
is
a
strange
comment
on
the
overall
views
of
the
greatest
leaders
the
world's
elite
class
has
ever
known.
Not
ever!

Sample code
// The name of this file is "read_num_file.c"
//
// This program reads numbers from the file numbers.txt,
// calculates the sum of all the numbers, and reports thetotal.
//

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

int main()
{
    FILE *infile = NULL;    //Declare a new input file pointer
    int newval = 0;
    int total = 0;

    infile = fopen("numbers.txt", "r"); //open numbers.txt in read mode
    if (infile == NULL)   // check to makesure the file opened properly
    {
        printf("Error openingfile ");
        exit(1);
    }

      // The following is one method ofreading and summing the numbers

//    while (fscanf(infile, "%d",&newval) != EOF)
//    {
//    printf("%d ", newval);
//    total += newval;
//    }


// Here is a different way. Notice that we have tocheck for EOF
// again after reading the file but before using thevalue
  
    while (!feof(infile))
    {
       fscanf(infile, "%d",&newval);
       if (!feof(infile))  // using feof() instead of fscanf()
       {
          printf("%d ", newval);
           total+= newval;
       }
    }

    fclose(infile); // Always remember to close afile when done

    printf("The sum of all the numbers innumbers.txt is: %d ", total);
   
    exit(0); // Just in case any files remainopen, this will close them.
    system("pause");
}


Sample code
// This file is named "write_num_file.c"
//
// This program prompts the user to enter five numbers. It writesthe
// numbers to the file output.txt, and also writes the total ofthe
// numbers to the file.

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

int main()
{
    FILE *outfile = NULL; // Declare newoutput file pointer
    int newVal = 0;
    int i = 0;
    int total = 0;

    outfile = fopen("output.txt", "w"); //Open output.txt for writing
    if (outfile == NULL)     //Check to make sure the file opened correctly
    {
        printf("Error openingfile ");
        exit(1);
    }

    for (i = 0; i < 5; i++)   // fivevalues are desired
    {
        printf("Enter a number-> "); // Prompt user for input
        scanf("%d",&newVal);    // read user input
        total += newVal; // Add new number to total

        // Print formattednumber to the output file
        fprintf(outfile, "Number%d is: %d ", (i+1), newVal);
    } // end for loop

               // print total sum of numbers to output file
    fprintf(outfile, "The sum of your numbers is:%d ", total);

    fclose(outfile); // Always close fileswhen you are finished with them
    exit (0); // Just in case any files areleft open, this will close them.
}


Explanation / Answer

please rate - thanks #include #include #include int main() {char word[20]; char save[50][20]; FILE *in, *out; int i=0,count=0,j; in = fopen("code.txt","r");    if(in == NULL)         {printf("Error openinginput file! ");         getch();         exit(1);         } out = fopen("message.txt","w");    if(in == NULL)         {printf("Error openingoutput file! ");         getch();         exit(1);        }       while (fscanf(in, "%s", &word) != EOF)    {printf("%s ",word);    i++;    if(i%10==0)        printf(" ");    if(i%5==0)       {j=0;         do          {save[count][j]=word[j];          }while(save[count][j++]!='');        count++;        }    }   printf(" Your decoded message says: "); for(i=0;i