Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program using C that prompts the user to enter the name of a file. The program finds the pairs of encoded/decoded words in

Write a program using C that prompts the user to enter the name of a file. The program finds the pairs of encoded/decoded words in the file.

input: Enter the file name: words.txt

output: encoded/decoded words are written to file: words.txt.sft

The program reads the content of the file and stores the words in an array of strings, the program then finds the pairs of encoded/decoded words and writes them to then ouput file.

1. Name your program file_search.c. The output file should be the same name as the input file but with an added extension of .sft. In this example the original file name is words.txt. The output file name is then words.txt.sft. Assume the file name is no more than 100 characters. Assume the length of each line in the input file is no more than 100 characters. Assume the input file contains no less than 1000 words.

2. In the program use the shift function (see image) to help search for pairs of encoded/decoded words. The function shifts the alphabetical letters 'message' in by shift_amount. 'Message' is a string containing the word to be encoded and shift_message is the string containing the word after being shifted by shift_amount. shift_amount represents the amount by which each letter in the message is to be shifted, in the range of 0 to 25. Lower-case letters remain lower-case when shifted. Upper case letters remain uppwe case. For example, if the 'message' is "make" and the shift_amount is 3, the function will assign shift_message to "pdnh". If the message is "Jr" and the shift_amount is 23, then function will modify message to "Go".

Note: words in the file could be pairs of encoded/decoded of any shift amount in the range of 0-26.

3. The output file should be in the following format: The output file contains all the unique encoded/decoded pairs in the input file.

1 nwlxmn

encode

2 nwlxmn

clambc

You must use the following:

words.txt file:

nwlxmn

hello

flee

dkllo

amount

function

program

search

jgnnq

crack

dsbdl

encode

shift

decode

khoor

message

defend

mnonwm

clambc

string

Shift.c function:

#include #include #define WORD_LEN 100 int read_line(char *str, int n); void shift(char *message, int shift_amount, char *shift_message); int main() { int shift_amount; char sen1[WORD_LEN+1]; char sen2[WORD_LEN+1]; printf("Please enter a sentence: "); read_line(sen1, 100); printf("Please enter the shift amount:"); scanf("%d", &shift_amount); shift(sen1, shift_amount, sen2); printf("The encoded sentence is:"); printf("%s ", sen2); return 0; } int read_line(char *str, int n) { int ch, i =0; while ((ch = getchar()) != ' ') {// printf("reading %c", ch); if (i= 'a' && *message <= 'z') *shift_message++ = (*message - 'a' + shift_amount)% 26 + 'a'; else if(*message >= 'A' && *message <= 'Z') *shift_message++ = (*message - 'A' + shift_amount)% 26 + 'A'; else *shift_message++ = *message; } *shift_message='\0'; }

Thank you! Please post a screenshot of the code rather than pasting it (the formatting gets messed up sometimes).

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamentals Of Database Management Systems

Authors: Mark L. Gillenson

2nd Edition

0470624701, 978-0470624708

More Books

Students also viewed these Databases questions