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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:54:22+00:00 2026-06-17T02:54:22+00:00

I have a problem parsing in c with sscanf I read a text on

  • 0

I have a problem parsing in c with sscanf

I read a text on console with one function called read_line()

char cm1[100],cm2[100],cm3[100]
printf("Enter command:");
read_line(var_text);
/*var_text = cat /etc/passwd | cut -f1 d: | sort */
int num = sscanf(var_text,"%s | %s | %s",cm1,cm2,cm3);

Ok if i write in var_text cat | cut | sort in cm1 return cat in cm2 return cut and in cm3 return sort, but if i write cat /etc/passwd | cut -f1 d: | sort , cm1 return cat and cm2 and cm3 none…

I’m made a shell in c, and i need the commands and atributes

Thx for all, and sorry for that bad english 🙂

  • 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-17T02:54:23+00:00Added an answer on June 17, 2026 at 2:54 am

    The %s format specifier will stop processing at the first whitespace character. In the case of:

    cat /etc/passwd | cut -f1 d: | sort

    it will be the space after the cat at which the first %s will end. The format specifier then expects a | which does not exist and cm2 and cm3 are not populated. You could use a scanset to achieve this:

    if (3 == sscanf(var_text, "%99[^|]| %99[^|]| %99s", cm1, cm2, cm3))
    {
    }
    

    Note use of width specifier to prevent buffer overrun and checking of return value from sscanf() to ensure all target variables were populated.

    The format specifier %99[^|] is stating read at most 99 characters (one less than the target buffer size to accomodate the null terminator) until a | character is encountered.

    See demo at http://ideone.com/Cz1Qef .

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

Sidebar

Related Questions

I have one problem with parsing *.docx document with OpenXML (C#). So, here's my
I am parsing xml file with simplexml_load_file() function. I have problem when i meet
I have a problem parsing with PHP Simple HTML DOM -lib. HTML: <td> <span>text</span>
Hi i have some problem with xml parsing. So - i want to read
I have a problem with parsing the contents of a char[]. It contains bytes,
I have a problem parsing a XML file which contains special characters like ,
Ok, I have a very frustrating problem. I am parsing a webpage and need
I have problem with passing an argument to my simple function in jQuery: When
I seem to have a problem passing some strings on from one form to
I have problem with parsing XML file using XLTS. <html xmlns=http://www.w3.org/1999/xhtml xml:lang=pl> <body style=margin-top:

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.