Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9300119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T22:42:44+00:00 2026-06-18T22:42:44+00:00

program Test implicit none character (LEN=100) :: input character (LEN=100) :: output print *,Please

  • 0
program Test

implicit none
character (LEN=100) :: input
character (LEN=100) :: output
print *,"Please input your message: "
read *, input

For every character, I encrypt it in Ceaser’s Cipher

Calculations

print *,"This is the output: "
write (*,"(2a)") "Message = ", out

end program Test

This doesn’t work entirely.

For every character in the input, I convert it using the modulo(iachar()) functions. It works up until the print, I followed the debugging, the encryption is fine.
But the issue with the output lies in LEN=100. The do loop will go through 100 times converting nonexistent characters into garbage, breaking the program at output with UNDEFINED TYPE.

So if I input “test”, it will encrypt CBNC*GARBAGE-TO-100* and not output. If I define length as 4, and do it, it works. but I want to be able to do it without defining a length. Any way around this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T22:42:46+00:00Added an answer on June 18, 2026 at 10:42 pm

    The read statement should pad input out to the full length of the variable (100 characters) with blanks, rather than adding “garbage”. The LEN_TRIM intrinsic function will give the significant length of the variable’s value – i.e. the length excluding trailing blanks. You may need to remember this significant length of the input string for when you print the output string.

    (Note the rules on list directed input (indicated by the * in the read statement) can be a little surprising – a format of “(A)” may be more robust, depending on the behaviour your want.)

    In terms of avoiding fixed length strings in the context of reading input – Fortran 2003 introduces deferred length character, which greatly helps here. Otherwise see Reading a character string of unknown length for Fortran 95 possibilities. One complication is that you are reading from the console, so the backspace statement may not work. The work around to that follows a similar approach to that linked, but necessitates piecewise building the input string into an allocatable array of character at the same time as the input record length is being determined. Sequence association is then used to convert that array into a scalar of the right length. Comment or ask again if you want more details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my program: program test implicit none integer n,m,k,i,j,Errorflag real :: Yabs(39,39),angle(39,39) real
Here is my minimal example: program test implicit none real :: testfunc write(*,*) Writing
I am somewhat puzzled by the following program module test implicit none type TestType
I have a simple program test which gets a number as input and prints
UPDATE: My modified code looks like this: program run_module_test use module_test implicit none TYPE(newXYZ),
How could I tell the program test.exe (which is a console application) to output
Is there a Perl module which can test the CGI output of another program?
I write a test program for Android, I record audio from mic and use
I created a program called test: #include<stdlib.h> #include<iostream> int main() { std::cout<<system(..\\add\\debug\\add.exe 4 8);
I wrote a test program to monitor my Picture folder which points to c:\users[username]\Pictures

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.