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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:25:13+00:00 2026-06-12T18:25:13+00:00

I have a multiline TSV file with the following format: Type\tBasic Name\tAttribute\tA Long Description\n

  • 0

I have a multiline TSV file with the following format:

Type\tBasic Name\tAttribute\tA Long Description\n

As you can see, the Basic Name and the Description can both contain some number of spaces. I am trying to read each line in and extract the elements. For now, I’ve narrowed it down to just extracting the basic name. My fscanf is as follows:

fscanf(file_in, "%*[^ ]s\t%128[^ ]s\t%*[^ ]s\t%[^ ]s\n", name_string, desc_string);

This doesn’t work as I have hoped, and I’m having trouble narrowing down the error. Does anyone know how I could read in the lines properly?

  • 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-06-12T18:25:14+00:00Added an answer on June 12, 2026 at 6:25 pm

    I mostly agree with Pablo (that the scanf family don’t make great parsers), but it’s worth understanding how to write a scanf pattern. The pattern you’re looking for is something like this:

    fscanf(" %*[^\t] %128[^\t] %*[^\t] %128[^\n]", name_string, desc_string)
    

    Notes:

    1. %[xyz] is a directive. %[xyz]s is two directives, the second of which matches a literal s

    2. As far a I know, there is no way to match a single literal tab character, since any whitespace in the pattern matches any amount of whitespace (including none) in the input. I used a space in my example, which will match a terminating tab, but it will also match any number of consecutive tabs so empty fields won’t be parsed correctly.

    3. The 128-character limit does not include the terminating NUL character.

    4. Also, if the scan stops because the chracter limit is exceeded, it won’t skip the rest of the field automatically, so you’ll end up out of synch with the input.

    A better pattern would be:

    fscanf(" %*[^\t] %128[^\t]%*[^\t] %*[^\t] %128[^\n]%*[^\n]", name_string, desc_string)
    

    which explicitly skips the remaining characters in the field, if necessary. An even better solution would be to use the a modifier and get fscanf to malloc memory for you.

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

Sidebar

Related Questions

I have a multiline textbox that contains very long text in it. How can
I have an multiline input string of following format ID | Col1 | Col2
I have a Multiline Textbox . I donot want to let user type HTML
In Python you can have a multiline string like this using a docstring foo
I have this regex: ^\/\* to check and see if a file contains those
If I have a multiline array and it contains for example the following integers
I really can't find this answer... I have multiline NSString called myString in XCode,
I have a multiline TextBox for which any of the following inputs are valid:
I need to model a postal address that can have multiline street address, the
I have a number of multiline macros defined in a file called macros.h. In

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.