# Reading and printing characters from a file

**URL:** <https://discourse.julialang.org/t/reading-and-printing-characters-from-a-file/123079>\
**Category:** New to Julia\
**Created:** [November 26, 2024, 7:21am UTC](https://discourse.julialang.org/t/reading-and-printing-characters-from-a-file/123079 "2024-11-26T07:21:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [November 26, 2024, 7:21am UTC](https://discourse.julialang.org/t/reading-and-printing-characters-from-a-file/123079/1 "2024-11-26T07:21:10Z")

</div>

Hello,  
I have a file like below:

```julia
A B c

```

I want to write a program that produces output like the following:

```julia
A is Uppercase
B is Uppercase
c is Lowercase

```

I wrote the following program:

```julia
function UL()
    inn = open("input.txt","r")
    while !eof(inn)
        if isuppercase(read(inn, Char))
            println("$(read(inn, Char)) is Uppercase")
        else
            println("$(read(inn, Char)) is Lowercase")
        end
    end
end

UL()

```

But output is:

```julia
is Uppercase
is Uppercase
is Lowercase

```

Why?

Thank you.

---

<div class="post-metadata">

**Author:** ![barucden](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/barucden/32/26154_2.png) [@barucden](https://discourse.julialang.org/u/barucden)\
**Post date:** [November 26, 2024, 8:00am UTC](https://discourse.julialang.org/t/reading-and-printing-characters-from-a-file/123079/2 "2024-11-26T08:00:35Z")

</div>

`read(inn, Char)` reads a single `Char` from the input stream. You call `read` once in the `if` condition, which reads the letters from your file, and then you call `read` the second time when printing, which reads the spaces from your file.

---

<div class="post-metadata">

**Author:** ![hack3rcon](https://avatars.discourse-cdn.com/v4/letter/h/96bed5/32.png) [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Post date:** [November 26, 2024, 9:27am UTC](https://discourse.julialang.org/t/reading-and-printing-characters-from-a-file/123079/3 "2024-11-26T09:27:07Z")

</div>

Hi,  
Thank you.  
The corrected version is:

```julia
function UL()
    inn = open("input.txt","r")
    while !eof(inn)
        c = read(inn, Char)
        if isuppercase(c) && c!=' '
            println("$c is Uppercase")
        elseif islowercase(c) && c!=' '
            println("$c is Lowercase")
        end
    end
end
UL()

```
