Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cesar code
#1
I have problem with cesar code. I would like encode my file: text.txt

from:
"I have dog"
to:
"L kdyh grj" (+3 to code of sign)

But I dont know how to read text from file sign to sing.

For read text (whole line) from file I use:
OPEN "filename" FOR INPUT AS #1
INPUT #1, text
CLOSE 1
Reply
#2
1. use LINE INPUT instead of INPUT when reading from the file. That way, a comma in the text string won't be counted as a delimiter. Also, it might have been a typo, but CLOSE 1 should be CLOSE #1.

2. once you've read in the string, use MID$() to look at the individual letters:

Code:
Letter$ = MID$(TextString$, LocationWithinString%, 1)

3. then you can use ASC() and CHR$() to do the +3 to the letter:

Code:
Letter$ = CHR$( ASC( Letter$ ) + 3 )

*peace*

Meg.
Reply
#3
Thanks Smile
I have one more problem.
I would like to know how long is "TextString$"

"I have dog" ("L kdyh grj") have 10 characters. Can QBasic count how many characters is in TextString$.
Reply
#4
LEN(str$) returns the length of str$
8% of the teenage population smokes or has smoked pot. If you're one of the 2% who hasn't, copy and paste this in your signature.
Reply
#5
Thanks Smile
Everything work correctly Big Grin
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)