Question

Write a C program to do the following: Read the contents of 3 files (BE340_Exam_A.txt, BE340_Exam_B.txt,...

Write a C program to do the following:

  • Read the contents of 3 files (BE340_Exam_A.txt, BE340_Exam_B.txt, BE340_Exam_C.txt)
  • Read each character from BE340_Exam_A, BE340_Exam_B, and BE340_Exam_C, and add them together to obtain each decrypted character
  • Write each decrypted character to an output file and also output each character to the screen
0 0
Add a comment Improve this question Transcribed image text
Answer #1

1 #include<stdio.h> 2 #include<string.h> #include<ctype.h> . 5 int main() 6 FILE fp1,*fp2 , *fp3 , *fp4; //opening files in r

#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(){
   FILE *fp1,*fp2,*fp3,*fp4;   
   //opening files in read mode
   fp1=fopen("BE340_Exam_A.txt","r");
   fp2=fopen("BE340_Exam_B.txt","r");
   fp3=fopen("BE340_Exam_C.txt","r");
  
   //opening output file in append mode
   fp4=fopen("output.txt","a");
   //declaring char variables
   char ch1,ch2,ch3;
   char ch[3];
  
   //getting characters from pointer
   ch1=fgetc(fp1);
   ch2=fgetc(fp2);
   ch3=fgetc(fp3);
   while (ch1!=EOF){ //if it is not end of the file
       if (isalpha(ch1) && isalpha(ch2) && isalpha(ch3)){ //if the characters are alphabets
           ch[0]=ch1;
           ch[1]=ch2;
           ch[2]=ch3;
           printf("%s",ch); //printing characters
           fprintf(fp4, "%s", ch); //appending characters to output file
       }
       ch1=fgetc(fp1);
       ch2=fgetc(fp2);
       ch3=fgetc(fp3);
   }
   printf("\n");
   return 0;
}

jack@jack-TravelMate-P243-M:~$ ./a.out AIQBJRCKSDLTEMUFNVGOWHPX jack@jack-TravelMate-P243 -M:~$ ]

I think this is the correct answer.

If you want any change comment me.

Add a comment
Know the answer?
Add Answer to:
Write a C program to do the following: Read the contents of 3 files (BE340_Exam_A.txt, BE340_Exam_B.txt,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to...

    File Encryption and Decryption chapter 9 programming exercise #3 Design and write a python program to successfully complete chapter 9 programming exercise #3. File Encryption and Decryption Write a program that uses a dictionary to assign “codes” to each letter of the alphabet. For example: codes = { ‘A’ : ‘%’, ‘a’ : ‘9’, ‘B’ : ‘@’, ‘b’ : ‘#’, etc . . .} Using this example, the letter A would be assigned the symbol %, the letter a would...

  • in c++ language, using quincy compiler Write a program that will read in 12 characters from...

    in c++ language, using quincy compiler Write a program that will read in 12 characters from the keyboard between a – z in lowercase. These letters will be inserted into a queue (imported from the Queue.h header file). When the 12th character has been entered, the queue will serve the characters one at a time to a character variable, which will push the values, one at a time, into a stack (using code imported from the Stack.h header file) and...

  • JAVA 6. Create two files and name them: puzzle.txt and puzzle2.txt Inside puzzle.txt, write the following...

    JAVA 6. Create two files and name them: puzzle.txt and puzzle2.txt Inside puzzle.txt, write the following text: MWTaahyiebt_e,c__hnyaoontuc;'e_rste_r_aynr_oert_e_gasoduoipdnp_got_shoeandtl__yty_oot_uhrree__apTdrH_oItgRhrDia_sml__eowtnotere.kr_ss_. Inside puzzle2.txt, write the following text: WTTohhriikssi__niigss,___ttbhhueet___wryrioogunh'gtr__emm_eessshssoaawggieen__gff_rrtoohmme___sswaarmmoppnllgee_22o..nttexxstt Open a file specified by the user. This file will contain a bunch of characters. You should read in each character from the file, one character at a time. Display every third character on the screen. Throw the other characters away. There is a sample input file called puzzle.txt, containing a little message you can...

  • program must be written in python and have commentary. thank you 3. File Encryption and Decryption...

    program must be written in python and have commentary. thank you 3. File Encryption and Decryption Write a program that uses a dictionary to assign "codes" to each letter of the alphabet. For example: codes-{A':'8','a' :'9', 'B' : e','b' :'#,, etc ) Using this example, the letter A would be assigned the symbol %, the letter a would be assigned the number 9, the letter B would be assigned the symbol e, and so forth. The program should open a...

  • Write a program in C++ that will read a sentence from the keyboard, terminated with a...

    Write a program in C++ that will read a sentence from the keyboard, terminated with a period '.' and write the sentence to an output file with all white spaces replaced by the symbol '*'. You may use the “isspace()” function of the “cctype” library to carry out the determination of whether the character read is 'white space'. Show any #include files you may need. Make sure to handle conditions where the file may be missing so your program does...

  • Write a C++ Program to do following: 1. Read every character from file char.txt using "get"...

    Write a C++ Program to do following: 1. Read every character from file char.txt using "get" and write it to a file char.bak using "put" 2. Read every second character from file char.txt using "get" and write it to a file charalternate.txt using "put" and "ignore" 3. Take input from user for offset and number of characters. For example if user enters 5 for offset and 10 for number of characters, then your program should copy 10 bytes from file...

  • C++ Lab 1. Read in the contents of a text file up to a maximum of...

    C++ Lab 1. Read in the contents of a text file up to a maximum of 1024 words – you create your own input. When reading the file contents, you can discard words that are single characters to avoid symbols, special characters, etc. 2. Sort the words read in ascending order in an array (you are not allowed to use Vectors) using the Selection Sort algorithm implemented in its own function. 3. Search any item input by user in your...

  • write program in C language. To get more practice working with files, you will write several...

    write program in C language. To get more practice working with files, you will write several functions that involve operations on files. In particular, implement the following functions 1. Write a function that, given a file path/name as a string opens the file and returns its entire contents as a single string. Any endline characters should be preserved char *getFileContents (const char filePath); 2. Write a function that, given a file path/name as a string opens the file and returns...

  • C++ please Write a program that reads the following sentences from a file: I am Sam...

    C++ please Write a program that reads the following sentences from a file: I am Sam Sam I am That Sam I am That Sam I am I do not like that Sam I am Do you like green eggs and ham I do not like them But I do like spam! You will first have to create the text file containing the input, separate from your program. Your program should produce two output files: (i) (ii) one with the...

  • Write a python program that prompts the user for the names of two text files and...

    Write a python program that prompts the user for the names of two text files and compare the contents of the two files to see if they are the same. If they are, the scripts should simply output “Yes”. If they are not, the program should output “No”, followed by the first lines of each file that differ from each other. The input loop should read and compare lines from each file. The loop should break as soon as a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT