I have a text file that appears to be in some type of code. Actually it is coded, with a very sophisticated code.
Here are the rules of the code (this is how the file was created.)
If a character is not an Alphabetic character do nothing to it.
If it is an alpha character shift it 3 backwards in the alphabet.
Don't forget to wrap the alphabet (e.g.. 'b' would become 'y')
Don't forget to handle upper and lower case (especially when wrapping.)
I am trying to write a C program that will decode the file. To do this the file should reverse the process.
The input file is provided. The program should read the input file, decode it, and write the output file. Make sure that you check for proper opening of the file and print an error message if the file does not exist. You should open the output file for write ('w'). Don't forget to close all files.
Here are some hints to get you started.
You will still pass non-alpha characters
You will shift up 3 letters (not back)
You will still need to wrap the ends of the alphabet
Remember that the computer thinks 'W'=87 (and 'w'=119)
fgets and fputs are your friends
You can assume a maximum length of the input line of 80
Your function should take the 2 strings for an argument
With completion with this question I will need the following to go along with the answer.
A source code (in a .c or a .cpp file)
A solution file (a .txt file with the decoded message in it)
A couple of paragraphs describing your approach to solving the problem.
I used this approach:
//begin
initialize your variables
open files that you will need
while not eof
read input file
call decode(instring, outstring)
write output file
close files
//end
function decode(instring, outstring)
initialize counter
looping through string
if alpha
if upper
process upper character
if lower
process lower character
else
pass non alpha charater
return from decode
Ql yb, lo klq ql yb-qexq fp qeb nrbpqflk:
Tebqebo 'qfp klyibo fk qeb jfka ql prccbo
Qeb pifkdp xka xooltp lc lrqoxdblrp cloqrkb
Lo ql qxhb xojp xdxfkpq x pbx lc qolryibp
Xka yv lmmlpfkd bka qebj. Ql afb, ql pibbm-
Kl jlob--xka yv x pibbm ql pxv tb bka
Qeb ebxoqxzeb, xka qeb qelrpxka kxqroxi pelzhp
Qexq cibpe fp ebfo ql. 'Qfp x zlkprjjxqflk
Abslrqiv ql yb tfpeba. Ql afb, ql pibbm-
Ql pibbm--mbozexkzb ql aobxj: xv, qebob'p qeb ory,
Clo fk qexq pibbm lc abxqe texq aobxjp jxv zljb
Tebk tb exsb percciba lcc qefp jloqxi zlfi,
Jrpq dfsb rp mxrpb. Qebob'p qeb obpmbzq
Qexq jxhbp zxixjfqv lc pl ilkd ifcb.
Clo tel tlria ybxo qeb tefmp xka pzlokp lc qfjb,
Qe' lmmobpplo'p tolkd, qeb molra jxk'p zlkqrjbiv
Qeb mxkdp lc abpmfpba ilsb, qeb ixt'p abixv,
Qeb fkplibkzb lc lccfzb, xka qeb pmrokp
Qexq mxqfbkq jbofq lc qe' rktloqev qxhbp,
Tebk eb efjpbic jfdeq efp nrfbqrp jxhb
Tfqe x yxob ylahfk? Tel tlria cxoabip ybxo,
Ql dorkq xka ptbxq rkabo x tbxov ifcb,
Yrq qexq qeb aobxa lc pljbqefkd xcqbo abxqe,
Qeb rkafpzlsboba zlrkqov, colj telpb ylrok
Kl qoxsbiibo obqrokp, mrwwibp qeb tfii,
Xka jxhbp rp oxqebo ybxo qelpb fiip tb exsb
Qexk civ ql lqebop qexq tb hklt klq lc?
Qerp zlkpzfbkzb albp jxhb zltxoap lc rp xii,
Xka qerp qeb kxqfsb erb lc obplirqflk
Fp pfzhifba l'bo tfqe qeb mxib zxpq lc qelrdeq,
Xka bkqbomofpb lc dobxq mfqze xka jljbkq
Tfqe qefp obdxoa qebfo zroobkqp qrok xtov
Xka ilpb qeb kxjb lc xzqflk. - Plcq vlr klt,
Qeb cxfo Lmebifx! - Kvjme, fk qev lofplkp
Yb xii jv pfkp objbjyboba.