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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T03:14:40+00:00 2026-05-17T03:14:40+00:00

I am attempting to parse a text (CSS) file using fscanf and pull out

  • 0

I am attempting to parse a text (CSS) file using fscanf and pull out all statements that match this pattern:

@import “some/file/somewhere.css”;

To do this, I have the following loop set up:

FILE *file = fopen(pathToSomeFile, "r");
char *buffer = (char *)malloc(sizeof(char) * 9000);

while(!feof(file))
{
    // %*[^@] : Read and discard all characters up to a '@'
    // %8999[^;] : Read up to 8999 characters starting at '@' to a ';'.
    if(fscanf(file, "%*[^@] %8999[^;]", buffer) == 1)
    {
        // Do stuff with the matching characters here.
        // This code is long and not relevant to the question.
    }
}

This works perfectly SO LONG AS the VERY FIRST character in the file is not a ‘@’. (Literally, a single space before the first ‘@’ character in the CSS file will make the code run fine.)

But if the very first character in the CSS file is a ‘@’, then what I see in the debugger is an infinite loop — execution enters the while loop, hits the fscanf statement, but does not enter the ‘if’ statement (fscanf fails), and then continues through the loop forever.

I believe my fscanf formatters may need some tweaking, but am unsure how to proceed. Any suggestions or explanations for why this is happening?

Thank you.

  • 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-17T03:14:41+00:00Added an answer on May 17, 2026 at 3:14 am

    Your format string does the following actions:

    • Read (and discard) 1 or more non-@ characters
    • Read (and discard) 0 or more whitespace characters (due to the space in the format string)
    • Read and store 1 to 8999 non-; characters

    Unfortunately, there is no format specifier for reading “zero or more” characters from a user-defined set.

    If you don’t care about multiple @include statements on a line, you could change your code to read a single line (with fgets), and then extract the @include statement from that (if the first character does not equal @, you can use your current format string with sscanf, otherwise, you could use sscanf(line, "%8999[^;]", buffer)).

    If multiple @include statemens on a line should be handled correctly, you could inspect the next character to be read with getc and then put it back with ungetc.

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

Sidebar

Related Questions

I am attempting to parse a XML file using Javascript and I'm running into
I have been attempting to write a VBA Script that can parse out other
I have become accustomed to using TryParse for attempting to parse unknown types: Dim
I'm attempting to parse a set of CSV data using PHP, but having a
I'm attempting to parse a JSON feed using the LastFM API but there are
I'm working on a C# class to parse BBCodes out of text pulled from
I am using Jsoup in my application and I am attempting to parse information
I'm attempting to parse newlines from pasted text from the clipboard into a single-lined
I am attempting to parse an output file for some data, and am having
I am attempting to parse text from a <cfoutput query=...> . I am interested

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.