1-byte chars

new topic     » topic index » view thread      » older message » newer message

--Strings of 1-byte chars
--and arrays of byte

include get.e
include machine.e
include misc.e

atom at
integer int,fn
sequence str,st,arr

int = 10

at = allocate(int)
mem_set(at,0,int)
str = peek({at,int})
free(at)

for i=1 to int do
  str[i] = '/'+i
end for
puts(1,"1) " & str & "\n")

st = str

str[2] = 64
puts(1,"2) " & str & "\n")

str[9] = str[2]
puts(1,"3) " & str & "\n")

str[3..4] = str[6..7]
puts(1,"4) " & str & "\n")

str &= st
puts(1,"5) " & str & "\n")

str = str[3..$-2]
puts(1,"6) " & str & "\n")

fn = open("bytes.txt","w")
puts(fn,str)
close(fn)

fn = open("bytes.txt","r")
str = gets(fn)
close(fn)
puts(1,"7) " & str & "\n\n")

fn = open("bytes1.txt","w")
puts(fn,str)
close(fn)

st = st[2..9]
st -= '0'
int = 8

arr = repeat(st,int)
for i=1 to int do
  arr[i][i] = 0
end for

fn = open("array_of_bytes.dat","wb")
for i=1 to int do
  puts(fn,arr[i])
end for
close(fn)

fn = open("array_of_bytes.dat","rb")
for i=1 to int do
  arr[i] = get_bytes(fn,int)
end for
close(fn)

for i=1 to int do
  str = arr[i]
  for j=1 to int do
    puts(1,sprint(str[j]) & " ")
  end for
  puts(1,"\n")
end for

int = wait_key()

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu