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

  • Home
  • SEARCH
  • 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 7572235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:52:29+00:00 2026-05-30T15:52:29+00:00

My program allows the user to specify a file which is read as input,

  • 0

My program allows the user to specify a file which is read as input, however this is optional. If the user does not specify a file, I’d like to read input in from the command line.

I have this so far:

main :: IO()
main = do
  (opts, mbArgs) <- parseCmdLine
  input <-
    case mbArgs of
      Nothing   -> getContents
      Just file -> readFile file

This doesn’t seem to be working. When a user doesn’t stipulate a file, they are able to enter input, but there seems to be no way of terminating so that the program can then work on that input.

I thought that you had to press Ctrl+D, but that doesn’t do anything.

Thanks for any help.

  • 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-05-30T15:52:30+00:00Added an answer on May 30, 2026 at 3:52 pm

    In a typical Unix-like terminal (such as Cygwin, at least in Cygwin’s rxvt; not sure about the Windows Command Prompt), a Ctrl+D only sends EOF when you’re at the start of a line. If you hit Enter and then Ctrl+D, it should work. If you want to send EOF without a newline, hit Ctrl+D twice in a row.

    If it’s not that, then there’s presumably some other problem with your terminal; the code looks fine.

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

Sidebar

Related Questions

I'm developing a program which allows users to input some information which then gets
This program allows a user to calculate to enter sales and calculate sales taxes
I am working on a program, which allows the user to lock the computer,
Currently my program allows the user to enter 5 integers which are used to
I need to create a program that allows a user to input a string
I'm trying to create a scorecard program which allows the user to select cells
I have created the following program which allows a user to guess a word
I am making a program that allows user to custom keyboard shortcuts, for this
I have a program that allows the user to enter a level number, and
I am finishing off a C# ASP.NET program that allows the user to build

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.