Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29427 Discussions

How to read a character string in memory as integer bytes?

anthonyrichards
New Contributor III
1,405 Views

I have successfully tried the IVF Encrypt/Decrypt samples on a character string held in a text file. Both programs take a source file and read the data into a buffer using unformatted READ, filling an integer buffer equal in length toa number of bytes in the file (the buffer is defined as INTEGER(BYTE) and pointed to by a pointer generated using MALLOC). After encryption/decryption, the result is written using unformatted WRITE to a destination text file.

What I am looking for is a way to modify the programs to replace thesource and destination text files by character strings in memory. Can anyone advise me of a way todothis? I am apparentlyforbidden from using internal unformatted READ/WRITES.

0 Kudos
2 Replies
Steven_L_Intel1
Employee
1,405 Views
You don't need to "read" the data - it's already in memory. Just pass LOC(string) and LEN(string), assuming the length is less than the algorithm's blocksize. If it's just a single string, there's not much else to do other than worrying about padding. If it's multiple strings then you probably know how long each one is supposed to be.
0 Kudos
anthonyrichards
New Contributor III
1,405 Views

Thanks, Steve, I will try that, which is much simpler than the fudge I found to work, namely:

EQUIVALENCE an INTEGER(1) ISTRING(256) to a CHARACTER(256) STRING

and then fill the INTEGER(1) BUFFER using

ICOUNT=0
....(some other stuff if a key-blob is written...)
DO I=1,LENGTH
ICOUNT=ICOUNT+1
BUFFER(ICOUNT)=ISTRING(I)
END DO

0 Kudos
Reply