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 430757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:54:25+00:00 2026-05-12T19:54:25+00:00

I wrote a short bit of code to simply skip num_lines lines in an

  • 0

I wrote a short bit of code to simply skip num_lines lines in an input file (printing the lines out for debugging purposes. Here’s two things I tried that didn’t work:

for i = 0 to num_lines do
  print_endline (fscanf infile "%s" (fun p -> p));
done;;

for i = 0 to num_lines do
  print_endline (fscanf infile "%S\n" (fun p -> p));
done;;

But this one did work:

for i = 0 to num_lines do
  print_endline (fscanf infile "%s\n" (fun p -> p));
done;;

I’ve been trying to comprehend the documentation on fscanf, but it doesn’t seem to be sinking in. Could someone explain to me exactly why the last snippet worked, but the first two didn’t?

  • 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-12T19:54:26+00:00Added an answer on May 12, 2026 at 7:54 pm

    “%s” — Matches everything to next white-space (“\n” here) but never matches “\n”

    “%S\n” — Matches thing that looks like Ocaml strings, then a “\n”

    “%s\n” — Matches everything to next white-space (“\n” here) then “\n”. This will act different if there is no trailing “\n” in file or if there is a space before the “\n”, etc.

    “%s ” — Matches anything up to white-space, and then all trailing white-space including “\n” (or possibly even no white-space). This works because ” ” means “any white space, possible none”, in the format string.

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

Sidebar

Related Questions

I wrote a short bash script to complete a task that involves creating a
So I wrote this short script (correct word?) to download the comic images from
I have an array of shorts (short[]) that I need to write out to
I wrote a simple batch file as a PowerShell script, and I am getting
Very basic question: how do I write a short literal in C++? I know
I write a lot of short throwaway programs, and one of the things I
What is the least amount of code you can write to create, sort (ascending),
Wrote the following in PowersHell as a quick iTunes demonstration: $iTunes = New-Object -ComObject
I am trying to write a JTextPane which supports some sort of coloring: as
The other day I decided to write an implementation of radix sort in Java.

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.