Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Reading in strings through read operation

Status
Not open for further replies.

Lloydone

Programmer
Jan 17, 2007
41
NZ
hey all,
I have come across a problem using the read operation to read in a particular character. It involves reading in a path name for a file which will inherently have '/' characters. It turns out my read code cannot read in these codes. Has anyone else come across this problem before ?

Any suggestions to fix it?
Regards,

Lloyd
 
Where is this read operation and path line?
A telepathy is a good thing but alas...
 
... and what compiler do you use. Salford for instance has some nice features to input pathnames.

Norbert
 
I use an Absoft compiler.

I read operation is in a subroutine that reads a series of strings from a file (which contain the '/' character) into an array.


Regards,

Lloyd
 
I circumvented the problem by making '/' a sting and concatenating the lot

 
Try
Code:
CHARACTER*80 line
READ(...,FMT='(A)') line ! get file line with slashes
then parse line by hands.
May be it helps...
 
Lloyd,

now I think know where the problem might be:

If you use only 'a' as format, the compiler adjusts the length of the format by the variable to be read - and might treat any 'special' character like '.' or '/' as delimiter.

Try to set the width of the format to your variable that is

character*50 variable
...
...

read(20,'(a50)')variable

I never encountered a prob this way reading ASCII characters (don't know about unicode though).

Norbert
 
Norbert,

Is this giving length to my variable or allocating more memory per character within my variable?



Regards ,

the forward slash bandit
 
The allocation of memory for your variable is done by your declaration, e.g.

character*50 string

assigns memory for 50 characters to your variable string.

The format '(a50)' in a read statement specifies, that the read statement is to read a field of 50 characters from your file. If your record is longer than 50 characters it will be truncated, if it is shorter the characters will be aligned to the left hand side in the variable, the remainder padded by blanks.

Norbert
 
Thanks for that,

Can you check the other recent thread of mine please Norbert

Regards,

Lloyd
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top